add dblclick event support (#3998)

* added double click

* added double click
This commit is contained in:
Andrea Bogazzi 2017-06-12 00:03:35 +02:00 committed by GitHub
parent 5f57659149
commit 57cc67300f
4 changed files with 15 additions and 14 deletions

View file

@ -33,6 +33,7 @@
* @fires mouse:up
* @fires mouse:over
* @fires mouse:out
* @fires mouse:doubleclick
*
*/
fabric.Canvas = fabric.util.createClass(fabric.StaticCanvas, /** @lends fabric.Canvas.prototype */ {

View file

@ -50,6 +50,7 @@
// mouse events
addListener(this.upperCanvasEl, 'mousedown', this._onMouseDown);
addListener(this.upperCanvasEl, 'dblclick', this._onDoubleClick);
addListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
addListener(this.upperCanvasEl, 'mouseout', this._onMouseOut);
addListener(this.upperCanvasEl, 'mouseenter', this._onMouseEnter);
@ -90,6 +91,7 @@
this._onMouseOut = this._onMouseOut.bind(this);
this._onMouseEnter = this._onMouseEnter.bind(this);
this._onContextMenu = this._onContextMenu.bind(this);
this._onDoubleClick = this._onDoubleClick.bind(this);
this.eventsBinded = true;
},
@ -105,7 +107,7 @@
removeListener(this.upperCanvasEl, 'mouseenter', this._onMouseEnter);
removeListener(this.upperCanvasEl, 'wheel', this._onMouseWheel);
removeListener(this.upperCanvasEl, 'contextmenu', this._onContextMenu);
removeListener(this.upperCanvasEl, 'doubleclick', this._onDoubleClick);
removeListener(this.upperCanvasEl, 'touchstart', this._onMouseDown);
removeListener(this.upperCanvasEl, 'touchmove', this._onMouseMove);
@ -212,13 +214,21 @@
return false;
},
/**
* @private
* @param {Event} e Event object fired on mousedown
*/
_onDoubleClick: function (e) {
var target;
this._handleEvent(e, 'dblclick', target);
},
/**
* @private
* @param {Event} e Event object fired on mousedown
*/
_onMouseDown: function (e) {
this.__onMouseDown(e);
addListener(fabric.document, 'touchend', this._onMouseUp, { passive: false });
addListener(fabric.document, 'touchmove', this._onMouseMove, { passive: false });

View file

@ -24,11 +24,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
this.fire('tripleclick', options);
this._stopEvent(options.e);
}
else if (this.isDoubleClick(newPointer)) {
this.fire('dblclick', options);
this._stopEvent(options.e);
}
this.__lastLastClickTime = this.__lastClickTime;
this.__lastClickTime = this.__newClickTime;
this.__lastPointer = newPointer;
@ -36,12 +31,6 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
this.__lastSelected = this.selected;
},
isDoubleClick: function(newPointer) {
return this.__newClickTime - this.__lastClickTime < 500 &&
this.__lastPointer.x === newPointer.x &&
this.__lastPointer.y === newPointer.y && this.__lastIsEditing;
},
isTripleClick: function(newPointer) {
return this.__newClickTime - this.__lastClickTime < 500 &&
this.__lastClickTime - this.__lastLastClickTime < 500 &&
@ -70,7 +59,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
* Initializes double and triple click event handlers
*/
initClicks: function() {
this.on('dblclick', function(options) {
this.on('mousedblclick', function(options) {
this.selectWord(this.getSelectionStartFromPointer(options.e));
});
this.on('tripleclick', function(options) {

View file

@ -37,6 +37,7 @@
* @fires mouseover
* @fires mouseout
* @fires mousewheel
* @fires mousedblclick
*/
fabric.Object = fabric.util.createClass(fabric.CommonMethods, /** @lends fabric.Object.prototype */ {