diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 8bad39d79..3fd204112 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -174,10 +174,6 @@ class BaseViewer extends EventEmitter { const fileExt = this.options.file.extension; this.fileLoadingIcon = getIconFromExtension(fileExt); this.startAt = getProp(this.options, `fileOptions.${this.options.file.id}.${FILE_OPTION_START}`, {}); - - if (EXCEL_EXTENSIONS.includes(fileExt) || IWORK_EXTENSIONS.includes(fileExt)) { - this.options.showAnnotationsControls = false; - } } this.finishLoadingSetup(); @@ -1011,7 +1007,7 @@ class BaseViewer extends EventEmitter { */ areAnnotationsEnabled() { // Do not attempt to fetch annotations if the user cannot create or view annotations - const { permissions } = this.options.file; + const { extension, permissions } = this.options.file; if (!this.hasAnnotationPermissions(permissions)) { return false; } @@ -1035,6 +1031,11 @@ class BaseViewer extends EventEmitter { return this.viewerConfig.enabled; } + // Disable new annotations for Excel and iWork formats + if (EXCEL_EXTENSIONS.includes(extension) || IWORK_EXTENSIONS.includes(extension)) { + this.options.showAnnotationsControls = false; + } + // Ignore viewer config if BoxAnnotations was pass into Preview as an option // Otherwise, use global preview annotation option return !!this.options.showAnnotations; diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index f9547a00a..b0e897c98 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -88,22 +88,6 @@ describe('lib/viewers/BaseViewer', () => { expect(base.annotatorPromiseResolver).to.not.be.undefined; }); - it('should not show annotations in toolbar if the file is excel or iWork formats', () => { - base.addCommonListeners = () => {}; - base.finishLoadingSetup = () => {}; - - base.options.file.extension = 'xlsx'; - base.options.showAnnotationsControls = true; - base.setup(); - expect(base.options.showAnnotationsControls).to.equal(false); - - base.isSetup = false; - base.options.file.extension = 'numbers'; - base.options.showAnnotationsControls = true; - base.setup(); - expect(base.options.showAnnotationsControls).to.equal(false); - }); - it('should add a mobile class to the container if on mobile', () => { base.isMobile = true; sandbox.stub(base, 'loadBoxAnnotations').returns(Promise.resolve()); @@ -1231,6 +1215,20 @@ describe('lib/viewers/BaseViewer', () => { expect(base.areAnnotationsEnabled()).to.be.false; }); + it('should not show annotations in toolbar if the file is excel or iWork formats', () => { + stubs.getViewerOption.withArgs('annotations').returns(null); + + base.options.file.extension = 'xlsx'; + base.options.showAnnotationsControls = true; + base.areAnnotationsEnabled(); + expect(base.options.showAnnotationsControls).to.equal(false); + + base.options.file.extension = 'numbers'; + base.options.showAnnotationsControls = true; + base.areAnnotationsEnabled(); + expect(base.options.showAnnotationsControls).to.equal(false); + }); + it('should use BoxAnnotations options if an instance of BoxAnnotations is passed into Preview', () => { stubs.getViewerOption.withArgs('annotations').returns(null); base.options.showAnnotations = false;