diff --git a/src/lib/annotations/Annotator.js b/src/lib/annotations/Annotator.js index 060ee901f..e8e8973d0 100644 --- a/src/lib/annotations/Annotator.js +++ b/src/lib/annotations/Annotator.js @@ -86,9 +86,10 @@ class Annotator extends EventEmitter { /** * Initializes annotator. * + * @param {number} [initialScale] - The initial scale factor to render the annotations * @return {void} */ - init() { + init(initialScale = 1) { this.annotatedElement = this.getAnnotatedEl(this.container); this.notification = new Notification(this.annotatedElement); @@ -106,7 +107,8 @@ class Annotator extends EventEmitter { this.setupMobileDialog(); } - this.setScale(1); + const scale = initialScale; + this.setScale(scale); this.setupAnnotations(); this.showAnnotations(); } diff --git a/src/lib/annotations/__tests__/Annotator-test.js b/src/lib/annotations/__tests__/Annotator-test.js index fe8d45c92..4d6ece2af 100644 --- a/src/lib/annotations/__tests__/Annotator-test.js +++ b/src/lib/annotations/__tests__/Annotator-test.js @@ -96,6 +96,7 @@ describe('lib/annotations/Annotator', () => { beforeEach(() => { const annotatedEl = document.querySelector('.annotated-element'); sandbox.stub(annotator, 'getAnnotatedEl').returns(annotatedEl); + annotator.annotatedElement = annotatedEl; stubs.scale = sandbox.stub(annotator, 'setScale'); stubs.setup = sandbox.stub(annotator, 'setupAnnotations'); @@ -105,8 +106,8 @@ describe('lib/annotations/Annotator', () => { }); it('should set scale and setup annotations', () => { - annotator.init(); - expect(stubs.scale).to.be.called; + annotator.init(5); + expect(stubs.scale).to.be.calledWith(5); expect(stubs.setup).to.be.called; expect(stubs.show).to.be.called; expect(annotator.annotationService).to.not.be.null; @@ -161,6 +162,7 @@ describe('lib/annotations/Annotator', () => { describe('once annotator is initialized', () => { beforeEach(() => { const annotatedEl = document.querySelector('.annotated-element'); + annotator.annotatedElement = annotatedEl; sandbox.stub(annotator, 'getAnnotatedEl').returns(annotatedEl); sandbox.stub(annotator, 'setupAnnotations'); sandbox.stub(annotator, 'showAnnotations'); diff --git a/src/lib/annotations/doc/DocAnnotator.js b/src/lib/annotations/doc/DocAnnotator.js index 70421b4ea..88d8e6f06 100644 --- a/src/lib/annotations/doc/DocAnnotator.js +++ b/src/lib/annotations/doc/DocAnnotator.js @@ -296,7 +296,7 @@ class DocAnnotator extends Annotator { } else if (type === TYPES.point) { thread = new DocPointThread(threadParams); } else { - throw new Error(`DocAnnotator: Unknown Annotation Type: ${type}`); + throw new Error(`Unhandled document annotation type: ${type}`); } this.addThreadToMap(thread); @@ -576,7 +576,7 @@ class DocAnnotator extends Annotator { return; } - // Determine if mouse is over any highlight dialog currently + // Determine if mouse is over any highlight dialog // and ignore hover events of any highlights below const event = this.mouseMoveEvent; if (docAnnotatorUtil.isDialogDataType(event.target)) { diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 25d0041d4..7b4955688 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -344,7 +344,9 @@ class BaseViewer extends EventEmitter { // Add a resize handler for the window document.defaultView.addEventListener('resize', this.debouncedResizeHandler); - this.addListener('load', () => { + this.addListener('load', (event) => { + ({ scale: this.scale = 1 } = event); + if (this.annotationsPromise) { this.annotationsPromise.then(this.loadAnnotator); } @@ -653,7 +655,8 @@ class BaseViewer extends EventEmitter { locale: location.locale, previewUI: this.previewUI }); - this.annotator.init(); + + this.annotator.init(this.scale); // Disables controls during point annotation mode this.annotator.addListener('annotationmodeenter', this.disableViewerControls); diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index cf5e54a47..1b131bb02 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -744,9 +744,11 @@ describe('lib/viewers/BaseViewer', () => { } }; base.addListener = sandbox.stub(); + base.scale = 1.5; base.annotator = { init: sandbox.stub(), - addListener: sandbox.stub() + addListener: sandbox.stub(), + setScale: sandbox.stub() }; base.annotatorConf = { CONSTRUCTOR: sandbox.stub().returns(base.annotator) @@ -754,7 +756,7 @@ describe('lib/viewers/BaseViewer', () => { base.initAnnotations(); }); it('should initialize the annotator', () => { - expect(base.annotator.init).to.be.called; + expect(base.annotator.init).to.be.calledWith(1.5); expect(base.annotator.addListener).to.be.calledWith('annotationmodeenter', sinon.match.func); expect(base.annotator.addListener).to.be.calledWith('annotationmodeexit', sinon.match.func); expect(base.annotator.addListener).to.be.calledWith('annotationsfetched', sinon.match.func); diff --git a/src/lib/viewers/doc/DocBaseViewer.js b/src/lib/viewers/doc/DocBaseViewer.js index 495f0bc96..b4dc9e77d 100644 --- a/src/lib/viewers/doc/DocBaseViewer.js +++ b/src/lib/viewers/doc/DocBaseViewer.js @@ -998,7 +998,8 @@ class DocBaseViewer extends BaseViewer { this.loaded = true; this.emit('load', { numPages: this.pdfViewer.pagesCount, - endProgress: false // Indicate that viewer will end progress later + endProgress: false, // Indicate that viewer will end progress later + scale: this.pdfViewer.currentScale }); } } diff --git a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js index a0d52ce55..75398f203 100644 --- a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js +++ b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js @@ -1436,7 +1436,8 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { docBase.pagesinitHandler(); expect(stubs.emit).to.be.calledWith('load', { endProgress: false, - numPages: 5 + numPages: 5, + scale: sinon.match.any }); expect(docBase.loaded).to.be.truthy; });