diff --git a/src/lib/annotations/Annotator.js b/src/lib/annotations/Annotator.js index 796026ae2..2908dd9dc 100644 --- a/src/lib/annotations/Annotator.js +++ b/src/lib/annotations/Annotator.js @@ -545,16 +545,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 } ]; @@ -616,26 +615,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 } ]; diff --git a/src/lib/annotations/__tests__/Annotator-test.js b/src/lib/annotations/__tests__/Annotator-test.js index 840c5d87f..df3588b9f 100644 --- a/src/lib/annotations/__tests__/Annotator-test.js +++ b/src/lib/annotations/__tests__/Annotator-test.js @@ -490,10 +490,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 @@ -508,11 +506,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 @@ -656,16 +652,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 diff --git a/src/lib/annotations/drawing/DrawingThread.js b/src/lib/annotations/drawing/DrawingThread.js index 97a01d180..0aeec7b19 100644 --- a/src/lib/annotations/drawing/DrawingThread.js +++ b/src/lib/annotations/drawing/DrawingThread.js @@ -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); } /**