From ac996793666ab700e5b48b803eb5d3e84cf0805d Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Wed, 8 Apr 2020 17:12:29 -0700 Subject: [PATCH 1/3] feat(annotations): Hide annotations when fullscreen is active --- src/lib/constants.js | 1 + src/lib/viewers/BaseViewer.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/lib/constants.js b/src/lib/constants.js index b9afc41cb..a88ad9c2d 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', + toggleVisibility: 'annotationtogglevisibility', }; export const BROWSERS = { diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index d267c0f0c..1418e160f 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -545,6 +545,7 @@ class BaseViewer extends EventEmitter { */ handleFullscreenEnter() { this.resize(); + this.emit(ANNOTATOR_EVENT.toggleVisibility); } /** @@ -554,6 +555,7 @@ class BaseViewer extends EventEmitter { */ handleFullscreenExit() { this.resize(); + this.emit(ANNOTATOR_EVENT.toggleVisibility); } /** From f299ad262cf90b4af4da9d125d11fbc160f8aba8 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Wed, 8 Apr 2020 17:45:05 -0700 Subject: [PATCH 2/3] feat(annotations): Address comments --- src/lib/viewers/BaseViewer.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 1418e160f..2122073fa 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -545,7 +545,9 @@ class BaseViewer extends EventEmitter { */ handleFullscreenEnter() { this.resize(); - this.emit(ANNOTATOR_EVENT.toggleVisibility); + if (this.annotator) { + this.annotator.emit(ANNOTATOR_EVENT.toggleVisibility); + } } /** @@ -555,7 +557,9 @@ class BaseViewer extends EventEmitter { */ handleFullscreenExit() { this.resize(); - this.emit(ANNOTATOR_EVENT.toggleVisibility); + if (this.annotator) { + this.annotator.emit(ANNOTATOR_EVENT.toggleVisibility); + } } /** From 1e2c49bb613d979f7f236bb0026504218aea6526 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Thu, 9 Apr 2020 13:54:12 -0700 Subject: [PATCH 3/3] feat(annotations): Emit event with parameter --- src/lib/constants.js | 2 +- src/lib/viewers/BaseViewer.js | 4 ++-- src/lib/viewers/__tests__/BaseViewer-test.js | 16 +++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/lib/constants.js b/src/lib/constants.js index a88ad9c2d..3529888f6 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -129,7 +129,7 @@ export const ANNOTATOR_EVENT = { fetch: 'annotationsfetched', error: 'annotationerror', scale: 'scaleannotations', - toggleVisibility: 'annotationtogglevisibility', + setVisibility: 'annotationsetvisibility', }; export const BROWSERS = { diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 2122073fa..49ea1dd69 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -546,7 +546,7 @@ class BaseViewer extends EventEmitter { handleFullscreenEnter() { this.resize(); if (this.annotator) { - this.annotator.emit(ANNOTATOR_EVENT.toggleVisibility); + this.annotator.emit(ANNOTATOR_EVENT.setVisibility, false); } } @@ -558,7 +558,7 @@ class BaseViewer extends EventEmitter { handleFullscreenExit() { this.resize(); if (this.annotator) { - this.annotator.emit(ANNOTATOR_EVENT.toggleVisibility); + 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); }); });