diff --git a/src/Annotator.js b/src/Annotator.js index 4f38f66c5..be570f726 100644 --- a/src/Annotator.js +++ b/src/Annotator.js @@ -396,13 +396,13 @@ class Annotator extends EventEmitter { } /** - * Resets any popoverUI on render/scale events + * Resets any annotation UI on render/scale events * * @param {number} [pageNum] - optional page number * @return {void} */ /* eslint-disable-next-line no-unused-vars */ - resetPopoverUI(pageNum?: number) {} + resetAnnotationUI(pageNum?: number) {} /** * Renders annotations from memory. @@ -410,11 +410,8 @@ class Annotator extends EventEmitter { * @return {void} */ render() { - this.resetPopoverUI(); - Object.keys(this.modeControllers).forEach((mode) => { - const controller = this.modeControllers[mode]; - controller.render(); - }); + this.resetAnnotationUI(); + Object.keys(this.modeControllers).forEach((mode) => this.modeControllers[mode].render()); } /** @@ -424,8 +421,8 @@ class Annotator extends EventEmitter { * @return {void} */ renderPage(pageNum: number) { + this.resetAnnotationUI(pageNum); Object.keys(this.modeControllers).forEach((mode) => this.modeControllers[mode].renderPage(pageNum)); - this.resetPopoverUI(pageNum); } /** diff --git a/src/doc/CreateHighlightDialog.js b/src/doc/CreateHighlightDialog.js index 031f8ecb4..2fd96843a 100644 --- a/src/doc/CreateHighlightDialog.js +++ b/src/doc/CreateHighlightDialog.js @@ -83,6 +83,7 @@ class CreateHighlightDialog extends EventEmitter { return; } + this.isVisible = false; const popoverLayers = this.container.querySelectorAll('.ba-dialog-layer'); if (!this.createPopoverComponent || popoverLayers.length === 0) { return; @@ -90,7 +91,6 @@ class CreateHighlightDialog extends EventEmitter { popoverLayers.forEach(unmountComponentAtNode); this.createPopoverComponent = null; - this.isVisible = false; } /** diff --git a/src/doc/DocAnnotator.js b/src/doc/DocAnnotator.js index 59a9f66c1..5bbe847eb 100644 --- a/src/doc/DocAnnotator.js +++ b/src/doc/DocAnnotator.js @@ -77,7 +77,7 @@ class DocAnnotator extends Annotator { // $FlowFixMe this.onSelectionChange = this.onSelectionChange.bind(this); // $FlowFixMe - this.resetPopoverUI = this.resetPopoverUI.bind(this); + this.resetAnnotationUI = this.resetAnnotationUI.bind(this); } /** @@ -243,7 +243,7 @@ class DocAnnotator extends Annotator { }; /** @inheritdoc */ - resetPopoverUI(pageNum?: number) { + resetAnnotationUI(pageNum?: number) { // $FlowFixMe document.getSelection().removeAllRanges(); if (this.highlighter) { @@ -328,7 +328,7 @@ class DocAnnotator extends Annotator { bindDOMListeners() { super.bindDOMListeners(); - this.container.addEventListener('resize', this.resetPopoverUI); + this.container.addEventListener('resize', this.resetAnnotationUI); // Highlight listeners on desktop & mobile if (this.plainHighlightEnabled || this.commentHighlightEnabled) { @@ -364,7 +364,7 @@ class DocAnnotator extends Annotator { unbindDOMListeners() { super.unbindDOMListeners(); - this.container.removeEventListener('resize', this.resetPopoverUI); + this.container.removeEventListener('resize', this.resetAnnotationUI); this.annotatedElement.removeEventListener('wheel', this.hideCreateDialog); this.annotatedElement.removeEventListener('touchend', this.hideCreateDialog); this.annotatedElement.removeEventListener('click', this.clickHandler); @@ -694,7 +694,7 @@ class DocAnnotator extends Annotator { highlightMouseupHandler = (event: Event) => { this.isCreatingHighlight = false; - if (!event || util.isInAnnotationOrMarker(event, this.container)) { + if (util.isInAnnotationOrMarker(event, this.container)) { return; } diff --git a/src/doc/__tests__/DocAnnotator-test.js b/src/doc/__tests__/DocAnnotator-test.js index 471a516a2..3f356d9a2 100644 --- a/src/doc/__tests__/DocAnnotator-test.js +++ b/src/doc/__tests__/DocAnnotator-test.js @@ -409,7 +409,7 @@ describe('doc/DocAnnotator', () => { }); }); - describe('resetPopoverUI()', () => { + describe('resetAnnotationUI()', () => { beforeEach(() => { document.getSelection = jest.fn().mockReturnValue({ removeAllRanges: jest.fn() @@ -421,13 +421,13 @@ describe('doc/DocAnnotator', () => { }); it('should clear and hide createHighlightDialog', () => { - annotator.resetPopoverUI(); + annotator.resetAnnotationUI(); expect(annotator.scaleAnnotationCanvases).not.toBeCalled(); expect(annotator.createHighlightDialog.unmountPopover).toBeCalled(); }); it('should scale annotation canvases if page number is provided', () => { - annotator.resetPopoverUI(1); + annotator.resetAnnotationUI(1); expect(annotator.scaleAnnotationCanvases).toBeCalledWith(1); expect(annotator.createHighlightDialog.unmountPopover).toBeCalled(); }); @@ -525,7 +525,7 @@ describe('doc/DocAnnotator', () => { it('should bind DOM listeners if user can annotate and highlight', () => { annotator.bindDOMListeners(); - expect(annotator.container.addEventListener).toBeCalledWith('resize', annotator.resetPopoverUI); + expect(annotator.container.addEventListener).toBeCalledWith('resize', annotator.resetAnnotationUI); expect(annotator.annotatedElement.addEventListener).toBeCalledWith( 'mouseup', annotator.highlightMouseupHandler @@ -634,7 +634,7 @@ describe('doc/DocAnnotator', () => { annotator.permissions.can_annotate = true; annotator.unbindDOMListeners(); - expect(annotator.container.removeEventListener).toBeCalledWith('resize', annotator.resetPopoverUI); + expect(annotator.container.removeEventListener).toBeCalledWith('resize', annotator.resetAnnotationUI); expect(annotator.annotatedElement.removeEventListener).toBeCalledWith( 'mouseup', annotator.highlightMouseupHandler