Skip to content

Commit

Permalink
Fix: Clarify separation between plain and comment highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Dec 1, 2017
1 parent 182233a commit 5698bb2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/Annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ class Annotator extends EventEmitter {
options
});

this.handleControllerEvents = this.handleControllerEvents.bind(this);
controller.addListener('annotationcontrollerevent', this.handleControllerEvents);
});
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/doc/CreateHighlightDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -92,6 +92,8 @@ class CreateHighlightDialog extends CreateAnnotationDialog {
this.onCommentPost = this.onCommentPost.bind(this);
this.onCommentCancel = this.onCommentCancel.bind(this);
}

this.createElement();
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/doc/DocAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 5698bb2

Please sign in to comment.