Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: annotation handler rebinding #294

Merged
merged 3 commits into from Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/lib/annotations/Annotator.js
Expand Up @@ -547,16 +547,15 @@ class Annotator extends EventEmitter {
* @return {void}
*/
bindPointModeListeners() {
const pointFunc = this.pointClickHandler.bind(this.annotatedElement);
const handlers = [
{
type: 'mousedown',
func: pointFunc,
func: this.pointClickHandler,
eventObj: this.annotatedElement
},
{
type: 'touchstart',
func: pointFunc,
func: this.pointClickHandler,
eventObj: this.annotatedElement
}
];
Expand Down Expand Up @@ -618,26 +617,23 @@ class Annotator extends EventEmitter {
return;
}

const startCallback = drawingThread.handleStart.bind(drawingThread);
const stopCallback = drawingThread.handleStop.bind(drawingThread);
const moveCallback = drawingThread.handleMove.bind(drawingThread);
/* eslint-disable require-jsdoc */
const locationFunction = (event) => this.getLocationFromEvent(event, TYPES.point);
/* eslint-enable require-jsdoc */
const handlers = [
{
type: 'mousemove',
func: annotatorUtil.eventToLocationHandler(locationFunction, moveCallback),
func: annotatorUtil.eventToLocationHandler(locationFunction, drawingThread.handleMove),
eventObj: this.annotatedElement
},
{
type: 'mousedown',
func: annotatorUtil.eventToLocationHandler(locationFunction, startCallback),
func: annotatorUtil.eventToLocationHandler(locationFunction, drawingThread.handleStart),
eventObj: this.annotatedElement
},
{
type: 'mouseup',
func: annotatorUtil.eventToLocationHandler(locationFunction, stopCallback),
func: annotatorUtil.eventToLocationHandler(locationFunction, drawingThread.handleStop),
eventObj: this.annotatedElement
}
];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/annotations/BoxAnnotations.js
Expand Up @@ -7,7 +7,7 @@ const ANNOTATORS = [
NAME: 'Document',
CONSTRUCTOR: DocAnnotator,
VIEWER: ['Document', 'Presentation'],
TYPE: [TYPES.point, TYPES.highlight]
TYPE: [TYPES.point, TYPES.highlight, TYPES.draw]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

},
{
NAME: 'Image',
Expand Down
10 changes: 0 additions & 10 deletions src/lib/annotations/__tests__/Annotator-test.js
Expand Up @@ -503,10 +503,8 @@ describe('lib/annotations/Annotator', () => {
it('should bind point mode click handler', () => {
sandbox.stub(annotator.annotatedElement, 'addEventListener');
sandbox.stub(annotator.annotatedElement, 'removeEventListener');
sandbox.stub(annotator.pointClickHandler, 'bind', () => annotator.pointClickHandler);

annotator.bindPointModeListeners();
expect(annotator.pointClickHandler.bind).to.be.called;
expect(annotator.annotatedElement.addEventListener).to.be.calledWith(
'mousedown',
annotator.pointClickHandler
Expand All @@ -521,11 +519,9 @@ describe('lib/annotations/Annotator', () => {
describe('unbindModeListeners()', () => {
it('should unbind point mode click handler', () => {
sandbox.stub(annotator.annotatedElement, 'removeEventListener');
sandbox.stub(annotator.pointClickHandler, 'bind', () => annotator.pointClickHandler);

annotator.bindPointModeListeners();
annotator.unbindModeListeners();
expect(annotator.pointClickHandler.bind).to.be.called;
expect(annotator.annotatedElement.removeEventListener).to.be.calledWith(
'mousedown',
annotator.pointClickHandler
Expand Down Expand Up @@ -669,16 +665,10 @@ describe('lib/annotations/Annotator', () => {
sandbox.stub(annotator.annotatedElement, 'addEventListener');
sandbox.stub(annotator.annotatedElement, 'removeEventListener');
sandbox.stub(annotator, 'isInDrawMode').returns(true);
sandbox.stub(drawingThread.handleStart, 'bind', () => drawingThread.pointClickHandler);
sandbox.stub(drawingThread.handleStop, 'bind', () => drawingThread.pointClickHandler);
sandbox.stub(drawingThread.handleMove, 'bind', () => drawingThread.pointClickHandler);
sandbox.stub(annotatorUtil, 'eventToLocationHandler').returns(locationHandler);

annotator.bindDrawModeListeners(drawingThread, postButtonEl);

expect(drawingThread.handleStart.bind).to.be.called;
expect(drawingThread.handleStop.bind).to.be.called;
expect(drawingThread.handleMove.bind).to.be.called;
expect(annotator.annotatedElement.addEventListener).to.be.calledWith(
sinon.match.string,
locationHandler
Expand Down
4 changes: 4 additions & 0 deletions src/lib/annotations/drawing/DrawingThread.js
Expand Up @@ -38,7 +38,11 @@ class DrawingThread extends AnnotationThread {
*/
constructor(data) {
super(data);

this.render = this.render.bind(this);
this.handleStart = this.handleStart.bind(this);
this.handleMove = this.handleMove.bind(this);
this.handleStop = this.handleStop.bind(this);
}

/**
Expand Down