From e898ec76a3eac04be0438368e5f7f3bbeefedfe3 Mon Sep 17 00:00:00 2001 From: Sumedha Pramod Date: Thu, 10 Aug 2017 13:18:01 -0700 Subject: [PATCH] Chore: Only remove annotation listeners if enabled on viewer --- src/lib/viewers/BaseViewer.js | 4 ++++ src/lib/viewers/__tests__/BaseViewer-test.js | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index 6308ae1d1..bbab51f35 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -722,6 +722,10 @@ class BaseViewer extends EventEmitter { * @return {boolean} Whether or not viewer is annotatable */ isAnnotatable(type) { + if (!this.annotatorConf) { + return false; + } + const { TYPE: annotationTypes } = this.annotatorConf; if (type && annotationTypes) { if (!annotationTypes.some((annotationType) => type === annotationType)) { diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index 3de92d51d..7acf547a2 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -806,6 +806,11 @@ describe('lib/viewers/BaseViewer', () => { sandbox.stub(base, 'areAnnotationsEnabled').returns(true); }); + it('should return false if annotations are not allowed on the current viewer', () => { + base.annotatorConf = undefined; + expect(base.isAnnotatable('point')).to.equal(false); + }) + it('should return true if the type is supported by the viewer', () => { expect(base.isAnnotatable('point')).to.equal(true); });