From a710b12f0d9a2d25b1e69c1bf55b905eb92aa02a Mon Sep 17 00:00:00 2001 From: Asturur Date: Mon, 12 Mar 2018 06:55:52 +0100 Subject: [PATCH] fixed multiple touchend --- src/mixins/canvas_events.mixin.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/mixins/canvas_events.mixin.js b/src/mixins/canvas_events.mixin.js index 182792b8ae3..3d55fcdfe14 100644 --- a/src/mixins/canvas_events.mixin.js +++ b/src/mixins/canvas_events.mixin.js @@ -12,7 +12,8 @@ }, addListener = fabric.util.addListener, removeListener = fabric.util.removeListener, - RIGHT_CLICK = 3, MIDDLE_CLICK = 2, LEFT_CLICK = 1; + RIGHT_CLICK = 3, MIDDLE_CLICK = 2, LEFT_CLICK = 1, + addEventOptions = { passive: false }; function checkClick(e, value) { return 'which' in e ? e.which === value : e.button === value - 1; @@ -61,8 +62,8 @@ addListener(this.upperCanvasEl, 'dragleave', this._onDragLeave); addListener(this.upperCanvasEl, 'drop', this._onDrop); // touch events - addListener(this.upperCanvasEl, 'touchstart', this._onMouseDown, { passive: false }); - addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, { passive: false }); + addListener(this.upperCanvasEl, 'touchstart', this._onMouseDown, addEventOptions); + addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, addEventOptions); if (typeof eventjs !== 'undefined' && 'add' in eventjs) { eventjs.add(this.upperCanvasEl, 'gesture', this._onGesture); @@ -250,11 +251,11 @@ */ _onMouseDown: function (e) { this.__onMouseDown(e); - addListener(fabric.document, 'touchend', this._onMouseUp, { passive: false }); - addListener(fabric.document, 'touchmove', this._onMouseMove, { passive: false }); + addListener(fabric.document, 'touchend', this._onMouseUp, addEventOptions); + addListener(fabric.document, 'touchmove', this._onMouseMove, addEventOptions); removeListener(this.upperCanvasEl, 'mousemove', this._onMouseMove); - removeListener(this.upperCanvasEl, 'touchmove', this._onMouseMove); + removeListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, addEventOptions); if (e.type === 'touchstart') { // Unbind mousedown to prevent double triggers from touch devices @@ -274,13 +275,13 @@ this.__onMouseUp(e); removeListener(fabric.document, 'mouseup', this._onMouseUp); - removeListener(fabric.document, 'touchend', this._onMouseUp); + removeListener(fabric.document, 'touchend', this._onMouseUp, addEventOptions); removeListener(fabric.document, 'mousemove', this._onMouseMove); - removeListener(fabric.document, 'touchmove', this._onMouseMove); + removeListener(fabric.document, 'touchmove', this._onMouseMove, addEventOptions); addListener(this.upperCanvasEl, 'mousemove', this._onMouseMove); - addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, { passive: false }); + addListener(this.upperCanvasEl, 'touchmove', this._onMouseMove, addEventOptions); if (e.type === 'touchend') { // Wait 400ms before rebinding mousedown to prevent double triggers