fixed multiple touchend (#4804)

This commit is contained in:
Andrea Bogazzi 2018-03-12 02:07:47 -04:00 committed by GitHub
parent 808faa6d5f
commit d105638e65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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