diff --git a/src/lib/annotations/AnnotationDialog.js b/src/lib/annotations/AnnotationDialog.js
index af0ae863c..8fd463e8b 100644
--- a/src/lib/annotations/AnnotationDialog.js
+++ b/src/lib/annotations/AnnotationDialog.js
@@ -4,14 +4,13 @@ import * as annotatorUtil from './annotatorUtil';
import * as constants from './annotationConstants';
import { ICON_CLOSE, ICON_DELETE } from '../icons/icons';
-const CLASS_ANNOTATION_PLAIN_HIGHLIGHT = 'bp-plain-highlight';
const CLASS_BUTTON_DELETE_COMMENT = 'delete-comment-btn';
const CLASS_CANCEL_DELETE = 'cancel-delete-btn';
const CLASS_CANNOT_ANNOTATE = 'cannot-annotate';
+const CLASS_COMMENT = 'annotation-comment';
const CLASS_COMMENTS_CONTAINER = 'annotation-comments';
const CLASS_REPLY_CONTAINER = 'reply-container';
const CLASS_REPLY_TEXTAREA = 'reply-textarea';
-const CLASS_ANIMATE_DIALOG = 'bp-animate-show-dialog';
const CLASS_DELETE_CONFIRMATION = 'delete-confirmation';
const CLASS_BUTTON_DELETE_CONFIRM = 'confirm-delete-btn';
@@ -23,6 +22,7 @@ class AnnotationDialog extends EventEmitter {
/**
* The data object for constructing a dialog.
+ *
* @typedef {Object} AnnotationDialogData
* @property {HTMLElement} annotatedElement HTML element being annotated on
* @property {Annotation[]} annotations Annotations in dialog, can be an
@@ -81,8 +81,9 @@ class AnnotationDialog extends EventEmitter {
annotatorUtil.showElement(this.element);
this.element.appendChild(this.dialogEl);
- if (this.highlightDialogEl && !this.hasComments) {
- this.element.classList.add(CLASS_ANNOTATION_PLAIN_HIGHLIGHT);
+ const commentEls = this.element.querySelectorAll(`.${CLASS_COMMENT}`);
+ if (this.highlightDialogEl && !commentEls.length) {
+ this.element.classList.add(constants.CLASS_ANNOTATION_PLAIN_HIGHLIGHT);
const headerEl = this.element.querySelector(constants.SELECTOR_MOBILE_DIALOG_HEADER);
headerEl.classList.add(constants.CLASS_HIDDEN);
@@ -91,7 +92,7 @@ class AnnotationDialog extends EventEmitter {
const dialogCloseButtonEl = this.element.querySelector(constants.SELECTOR_DIALOG_CLOSE);
dialogCloseButtonEl.addEventListener('click', this.hideMobileDialog);
- this.element.classList.add(CLASS_ANIMATE_DIALOG);
+ this.element.classList.add(constants.CLASS_ANIMATE_DIALOG);
this.bindDOMListeners();
}
@@ -146,14 +147,18 @@ class AnnotationDialog extends EventEmitter {
return;
}
- this.element.classList.remove(CLASS_ANIMATE_DIALOG);
+ if (this.dialogEl && this.dialogEl.parentNode) {
+ this.dialogEl.parentNode.removeChild(this.dialogEl);
+ }
+
+ this.element.classList.remove(constants.CLASS_ANIMATE_DIALOG);
// Clear annotations from dialog
this.element.innerHTML = `
`.trim();
- this.element.classList.remove(CLASS_ANNOTATION_PLAIN_HIGHLIGHT);
+ this.element.classList.remove(constants.CLASS_ANNOTATION_PLAIN_HIGHLIGHT);
const dialogCloseButtonEl = this.element.querySelector(constants.SELECTOR_DIALOG_CLOSE);
dialogCloseButtonEl.removeEventListener('click', this.hideMobileDialog);
@@ -162,9 +167,7 @@ class AnnotationDialog extends EventEmitter {
this.unbindDOMListeners();
// Cancel any unsaved annotations
- if (!this.hasAnnotations) {
- this.cancelAnnotation();
- }
+ this.cancelAnnotation();
}
/**
@@ -173,6 +176,10 @@ class AnnotationDialog extends EventEmitter {
* @return {void}
*/
hide() {
+ if (this.element && this.element.classList.contains(constants.CLASS_HIDDEN)) {
+ return;
+ }
+
if (this.isMobile) {
this.hideMobileDialog();
}
@@ -404,8 +411,7 @@ class AnnotationDialog extends EventEmitter {
// Clicking 'Cancel' button to cancel the annotation
case constants.DATA_TYPE_CANCEL:
if (this.isMobile) {
- // Hide mobile dialog without destroying the thread
- this.hideMobileDialog();
+ this.hide();
} else {
// Cancels + destroys the annotation thread
this.cancelAnnotation();
@@ -478,7 +484,7 @@ class AnnotationDialog extends EventEmitter {
const text = annotatorUtil.htmlEscape(annotation.text);
const annotationEl = document.createElement('div');
- annotationEl.classList.add('annotation-comment');
+ annotationEl.classList.add(CLASS_COMMENT);
annotationEl.setAttribute('data-annotation-id', annotation.annotationID);
annotationEl.innerHTML = `
${avatarHtml}
diff --git a/src/lib/annotations/AnnotationThread.js b/src/lib/annotations/AnnotationThread.js
index 45c2947ea..2ca882f66 100644
--- a/src/lib/annotations/AnnotationThread.js
+++ b/src/lib/annotations/AnnotationThread.js
@@ -367,7 +367,7 @@ class AnnotationThread extends EventEmitter {
* @return {void}
*/
cancelUnsavedAnnotation() {
- if (!this.isMobile && !annotatorUtil.isPending(this.state)) {
+ if (!annotatorUtil.isPending(this.state)) {
return;
}
this.destroy();
diff --git a/src/lib/annotations/Annotator.js b/src/lib/annotations/Annotator.js
index 7a35704ce..eec154e21 100644
--- a/src/lib/annotations/Annotator.js
+++ b/src/lib/annotations/Annotator.js
@@ -13,6 +13,7 @@ import {
CLASS_ANNOTATION_MODE,
CLASS_MOBILE_DIALOG_HEADER,
CLASS_DIALOG_CLOSE,
+ ID_MOBILE_ANNOTATION_DIALOG,
SELECTOR_ANNOTATION_BUTTON_DRAW_CANCEL,
SELECTOR_ANNOTATION_BUTTON_DRAW_ENTER,
SELECTOR_ANNOTATION_BUTTON_DRAW_POST,
@@ -56,6 +57,7 @@ class Annotator extends EventEmitter {
this.locale = data.locale;
this.validationErrorEmitted = false;
this.isMobile = data.isMobile;
+ this.hasTouch = data.hasTouch;
this.previewUI = data.previewUI;
this.modeButtons = data.modeButtons;
this.annotationModeHandlers = [];
@@ -195,6 +197,7 @@ class Annotator extends EventEmitter {
mobileDialogEl.classList.add(CLASS_MOBILE_ANNOTATION_DIALOG);
mobileDialogEl.classList.add(CLASS_ANNOTATION_DIALOG);
mobileDialogEl.classList.add(CLASS_HIDDEN);
+ mobileDialogEl.id = ID_MOBILE_ANNOTATION_DIALOG;
mobileDialogEl.innerHTML = `