From 72471f6318daa2011cac0c0d5dc636b43774b9ef Mon Sep 17 00:00:00 2001 From: Mingze Date: Thu, 9 Apr 2020 15:05:25 -0700 Subject: [PATCH] feat(annotations): Hide annotations when fullscreen is active (#1195) * feat(annotations): Hide annotations when fullscreen is active * feat(annotations): Address comments * feat(annotations): Emit event with parameter --- src/lib/constants.js | 1 + src/lib/viewers/BaseViewer.js | 6 ++++++ src/lib/viewers/__tests__/BaseViewer-test.js | 16 +++++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/lib/constants.js b/src/lib/constants.js index b9afc41cb..3529888f6 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -129,6 +129,7 @@ export const ANNOTATOR_EVENT = { fetch: 'annotationsfetched', error: 'annotationerror', scale: 'scaleannotations', + setVisibility: 'annotationsetvisibility', }; export const BROWSERS = { diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index d267c0f0c..49ea1dd69 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -545,6 +545,9 @@ class BaseViewer extends EventEmitter { */ handleFullscreenEnter() { this.resize(); + if (this.annotator) { + this.annotator.emit(ANNOTATOR_EVENT.setVisibility, false); + } } /** @@ -554,6 +557,9 @@ class BaseViewer extends EventEmitter { */ handleFullscreenExit() { this.resize(); + if (this.annotator) { + this.annotator.emit(ANNOTATOR_EVENT.setVisibility, true); + } } /** diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index 892e69938..0a4b10f3e 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -16,13 +16,7 @@ let base; let containerEl; let stubs = {}; const sandbox = sinon.sandbox.create(); -const ANNOTATOR_EVENT = { - modeEnter: 'annotationmodeenter', - modeExit: 'annotationmodeexit', - fetch: 'annotationsfetched', - error: 'annotationerror', - scale: 'scaleannotations', -}; +const { ANNOTATOR_EVENT } = constants; describe('lib/viewers/BaseViewer', () => { before(() => { @@ -532,20 +526,28 @@ describe('lib/viewers/BaseViewer', () => { describe('handleFullscreenEnter()', () => { it('should resize the viewer', () => { sandbox.stub(base, 'resize'); + base.annotator = { + emit: sandbox.mock(), + }; base.handleFullscreenEnter(); expect(base.resize).to.be.called; + expect(base.annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.setVisibility, false); }); }); describe('handleFullscreenExit()', () => { it('should resize the viewer', () => { sandbox.stub(base, 'resize'); + base.annotator = { + emit: sandbox.mock(), + }; base.handleFullscreenExit(); expect(base.resize).to.be.called; + expect(base.annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.setVisibility, true); }); });