Skip to content

Commit

Permalink
fixed multiple touchend (fabricjs#4804)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Mar 12, 2018
1 parent 48ae20d commit c94a6da
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c94a6da

Please sign in to comment.