diff --git a/src/Annotator.js b/src/Annotator.js index 04539ea20..cec645c42 100644 --- a/src/Annotator.js +++ b/src/Annotator.js @@ -282,7 +282,6 @@ class Annotator extends EventEmitter { options }); - this.handleControllerEvents = this.handleControllerEvents.bind(this); controller.addListener('annotationcontrollerevent', this.handleControllerEvents); }); } @@ -362,12 +361,17 @@ class Annotator extends EventEmitter { // Generate map of page to threads Object.keys(threadMap).forEach((threadID) => { const annotations = threadMap[threadID]; - const firstAnnotation = util.getFirstAnnotation(annotations); - if (!firstAnnotation || !this.isModeAnnotatable(firstAnnotation.type)) { + + // NOTE: Using the last annotation to evaluate if the annotation type + // is enabled because highlight comment annotations may have a plain + // highlight as the first annotation in the thread. + const lastAnnotation = util.getLastAnnotation(annotations); + if (!lastAnnotation || !this.isModeAnnotatable(lastAnnotation.type)) { return; } // Bind events on valid annotation thread + const firstAnnotation = util.getLastAnnotation(annotations); const thread = this.createAnnotationThread(annotations, firstAnnotation.location, firstAnnotation.type); const controller = this.modeControllers[firstAnnotation.type]; if (controller) { @@ -542,13 +546,9 @@ class Annotator extends EventEmitter { const pageThreads = this.threads[pageNum] || {}; Object.keys(pageThreads).forEach((threadID) => { - const thread = pageThreads[threadID]; - if (!this.isModeAnnotatable(thread.type)) { - return; - } - // Sets the annotatedElement if the thread was fetched before the // dependent document/viewer finished loading + const thread = pageThreads[threadID]; if (!thread.annotatedElement) { thread.annotatedElement = this.annotatedElement; } diff --git a/src/doc/CreateHighlightDialog.js b/src/doc/CreateHighlightDialog.js index cebc8b019..22a8d60c9 100644 --- a/src/doc/CreateHighlightDialog.js +++ b/src/doc/CreateHighlightDialog.js @@ -79,8 +79,8 @@ class CreateHighlightDialog extends CreateAnnotationDialog { constructor(parentEl, config = {}) { super(parentEl, config); - this.allowHighlight = !!config.allowHighlight || true; - this.allowComment = !!config.allowComment || true; + this.allowHighlight = config.allowHighlight || false; + this.allowComment = config.allowComment || false; // Explicit scope binding for event listeners if (this.allowHighlight) { @@ -92,6 +92,8 @@ class CreateHighlightDialog extends CreateAnnotationDialog { this.onCommentPost = this.onCommentPost.bind(this); this.onCommentCancel = this.onCommentCancel.bind(this); } + + this.createElement(); } /** diff --git a/src/doc/DocAnnotator.js b/src/doc/DocAnnotator.js index adc4fb41a..0b1168bc9 100644 --- a/src/doc/DocAnnotator.js +++ b/src/doc/DocAnnotator.js @@ -384,7 +384,6 @@ class DocAnnotator extends Annotator { allowHighlight: this.plainHighlightEnabled, localized: this.localized }); - this.createHighlightDialog.createElement(); this.createHighlightDialog.addListener(CREATE_EVENT.init, () => this.emit(THREAD_EVENT.pending, TYPES.highlight) diff --git a/src/util.js b/src/util.js index c968ef78d..190b43187 100644 --- a/src/util.js +++ b/src/util.js @@ -356,6 +356,18 @@ export function getFirstAnnotation(annotations) { return annotations[firstAnnotationId]; } +/** + * Return first annotation in thread + * + * @param {Object} annotations - Annotations in thread + * @return {Annotation} First annotation in thread + */ +export function getLastAnnotation(annotations) { + const numAnnotations = Object.keys(annotations).length; + const lastAnnotationID = Object.keys(annotations)[numAnnotations - 1]; + return annotations[lastAnnotationID]; +} + /** * Whether or not a highlight annotation has comments or is a plain highlight *