Skip to content

Commit

Permalink
Fix: Hiding annotations for the image viewer (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored and DanDeMicco committed May 18, 2018
1 parent 2f209d7 commit 8315778
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/controllers/AnnotationModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ class AnnotationModeController extends EventEmitter {

const pageThreads = this.threads[pageNum].all() || [];
pageThreads.forEach((thread, index) => {
thread.hideDialog();

// Sets the annotatedElement if the thread was fetched before the
// dependent document/viewer finished loading
if (!thread.annotatedElement) {
Expand Down
1 change: 1 addition & 0 deletions src/controllers/__tests__/AnnotationModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ describe('controllers/AnnotationModeController', () => {
controller.threads[1].insert(stubs.thread);
controller.threads[2].insert(stubs.thread);

stubs.threadMock.expects('hideDialog').once();
stubs.threadMock.expects('show').once();
controller.renderPage(1);
expect(stubs.thread.annotatedElement).to.equal('el');
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/__tests__/HighlightModeController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('controllers/HighlightModeController', () => {
location: { page: 1 },
type: TYPES.highlight,
show: () => {},
addListener: () => {}
addListener: () => {},
hideDialog: () => {}
};
stubs.threadMock = sandbox.mock(stubs.thread);
});
Expand Down
38 changes: 15 additions & 23 deletions src/image/ImageAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ class ImageAnnotator extends Annotator {
// Abstract Implementations
//--------------------------------------------------------------------------

/**
* Determines the annotated element in the viewer
*
* @param {HTMLElement} containerEl - Container element for the viewer
* @return {HTMLElement} Annotated element in the viewer
*/
/** @inheritdoc */
getAnnotatedEl(containerEl) {
return containerEl.querySelector(ANNOTATED_ELEMENT_SELECTOR);
}
Expand Down Expand Up @@ -86,16 +81,7 @@ class ImageAnnotator extends Annotator {
return location;
}

/**
* Creates the proper type of thread, adds it to in-memory map, and returns
* it.
*
* @override
* @param {Object} annotations - Annotations in thread
* @param {Object} location - Location object
* @param {string} [type] - Optional annotation type
* @return {AnnotationThread} Created annotation thread
*/
/** @inheritdoc */
createAnnotationThread(annotations, location, type) {
let thread;

Expand All @@ -122,13 +108,7 @@ class ImageAnnotator extends Annotator {
return thread;
}

/**
* Orient annotations to the correct scale and orientation of the annotated document.
*
* @private
* @param {Object} data - Scale and orientation values needed to orient annotations.
* @return {void}
*/
/** @inheritdoc */
scaleAnnotations(data) {
this.setScale(data.scale);
this.rotateAnnotations(data.rotationAngle, data.pageNum);
Expand Down Expand Up @@ -167,6 +147,18 @@ class ImageAnnotator extends Annotator {
util.showElement(pointAnnotateButton);
}
}

/** @inheritdoc */
bindDOMListeners() {
this.annotatedElement.addEventListener('mouseup', this.hideAnnotations);
super.bindDOMListeners();
}

/** @inheritdoc */
unbindDOMListeners() {
this.annotatedElement.removeEventListener('mouseup', this.hideAnnotations);
super.bindDOMListeners();
}
}

export default ImageAnnotator;

0 comments on commit 8315778

Please sign in to comment.