Skip to content

Commit

Permalink
feat(annotations): Hide annotations when fullscreen is active (#1195)
Browse files Browse the repository at this point in the history
* feat(annotations): Hide annotations when fullscreen is active

* feat(annotations): Address comments

* feat(annotations): Emit event with parameter
  • Loading branch information
Mingze committed Apr 9, 2020
1 parent 5c3f64b commit 72471f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const ANNOTATOR_EVENT = {
fetch: 'annotationsfetched',
error: 'annotationerror',
scale: 'scaleannotations',
setVisibility: 'annotationsetvisibility',
};

export const BROWSERS = {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ class BaseViewer extends EventEmitter {
*/
handleFullscreenEnter() {
this.resize();
if (this.annotator) {
this.annotator.emit(ANNOTATOR_EVENT.setVisibility, false);
}
}

/**
Expand All @@ -554,6 +557,9 @@ class BaseViewer extends EventEmitter {
*/
handleFullscreenExit() {
this.resize();
if (this.annotator) {
this.annotator.emit(ANNOTATOR_EVENT.setVisibility, true);
}
}

/**
Expand Down
16 changes: 9 additions & 7 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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);
});
});

Expand Down

0 comments on commit 72471f6

Please sign in to comment.