Skip to content

Commit

Permalink
Fix: Issue when 'load' event is fired before BoxAnnotations is loaded (
Browse files Browse the repository at this point in the history
…#108)

- Ensures that promise to load BoxAnnotations.js completes before loading annotations, even if the viewer 'load' event has already been fired
- Re-renders annotations on documents after resize
  • Loading branch information
pramodsum authored May 11, 2017
1 parent 93a5ba2 commit b4c8d32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class BaseViewer extends EventEmitter {
// the assets are available, the showAnnotations flag is true, and the
// expiring embed is not a shared link
if (this.areAnnotationsEnabled() && !this.options.sharedLink) {
this.loadAssets(ANNOTATIONS_JS, ANNOTATIONS_CSS);
this.annotationsPromise = this.loadAssets(ANNOTATIONS_JS, ANNOTATIONS_CSS);
}
}

Expand Down Expand Up @@ -278,8 +278,8 @@ class BaseViewer extends EventEmitter {
});

this.addListener('load', () => {
if (window.BoxAnnotations && this.areAnnotationsEnabled()) {
this.loadAnnotator();
if (this.areAnnotationsEnabled()) {
this.annotationsPromise.then(this.loadAnnotator);
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,10 @@ class DocBaseViewer extends BaseViewer {

this.setPage(currentPageNumber);

// Update annotations scale
// Update annotations scale to current numerical scale
if (this.annotator) {
this.annotator.setScale(this.pdfViewer.currentScale); // Set scale to current numerical scale
this.annotator.setScale(this.pdfViewer.currentScale);
this.annotator.renderAnnotations();
}

super.resize();
Expand Down
4 changes: 3 additions & 1 deletion src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,13 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {

it('should set the annotator scale if it exists', () => {
docBase.annotator = {
setScale: sandbox.stub()
setScale: sandbox.stub(),
renderAnnotations: sandbox.stub()
};

docBase.resize();
expect(docBase.annotator.setScale).to.be.called;
expect(docBase.annotator.renderAnnotations).to.be.called;
expect(stubs.setPage).to.be.called;
});
});
Expand Down

0 comments on commit b4c8d32

Please sign in to comment.