mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-20 03:11:52 +00:00
Added isClick boolean to mouseUp events on left click (#3898)
* added test * removed useless method
This commit is contained in:
parent
d1ec14f2de
commit
977d71de6e
2 changed files with 36 additions and 15 deletions
|
|
@ -357,34 +357,31 @@
|
|||
if (target) {
|
||||
target.isMoving = false;
|
||||
}
|
||||
|
||||
this._handleCursorAndEvent(e, target, 'up');
|
||||
this._setCursorFromEvent(e, target);
|
||||
this._handleEvent(e, 'up', target ? target : null, LEFT_CLICK, isClick);
|
||||
target && (target.__corner = 0);
|
||||
shouldRender && this.renderAll();
|
||||
},
|
||||
|
||||
/**
|
||||
* set cursor for mouse up and handle mouseUp event
|
||||
* @param {Event} e event from mouse
|
||||
* @param {fabric.Object} target receiving event
|
||||
* @param {String} eventType event to fire (up, down or move)
|
||||
*/
|
||||
_handleCursorAndEvent: function(e, target, eventType) {
|
||||
this._setCursorFromEvent(e, target);
|
||||
this._handleEvent(e, eventType, target ? target : null);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Handle event firing for target and subtargets
|
||||
* @param {Event} e event from mouse
|
||||
* @param {String} eventType event to fire (up, down or move)
|
||||
* @param {fabric.Object} targetObj receiving event
|
||||
* @param {Number} [button] button used in the event 1 = left, 2 = middle, 3 = right
|
||||
* @param {Boolean} isClick for left button only, indicates that the mouse up happened without move.
|
||||
*/
|
||||
_handleEvent: function(e, eventType, targetObj, button) {
|
||||
_handleEvent: function(e, eventType, targetObj, button, isClick) {
|
||||
var target = typeof targetObj === 'undefined' ? this.findTarget(e) : targetObj,
|
||||
targets = this.targets || [],
|
||||
options = { e: e, target: target, subTargets: targets, button: button || LEFT_CLICK };
|
||||
options = {
|
||||
e: e,
|
||||
target: target,
|
||||
subTargets: targets,
|
||||
button: button || LEFT_CLICK,
|
||||
isClick: isClick || false
|
||||
};
|
||||
this.fire('mouse:' + eventType, options);
|
||||
target && target.fire('mouse' + eventType, options);
|
||||
for (var i = 0; i < targets.length; i++) {
|
||||
|
|
|
|||
|
|
@ -1769,4 +1769,28 @@
|
|||
deepEqual(canvas._groupSelector, expectedGroupSelector, 'with object non selectable groupSelector is started');
|
||||
canvas.__onMouseUp(e);
|
||||
});
|
||||
|
||||
test('mouse:down and group selector isClick = true', function() {
|
||||
var e = { clientX: 30, clientY: 30, which: 1 };
|
||||
var isClick = false;
|
||||
canvas.on('mouse:up', function(opt) {
|
||||
isClick = opt.isClick;
|
||||
});
|
||||
canvas.__onMouseDown(e);
|
||||
canvas.__onMouseUp(e);
|
||||
equal(isClick, true, 'without moving the pointer, the click is true');
|
||||
});
|
||||
|
||||
test('mouse:down and group selector isClick = false', function() {
|
||||
var e = { clientX: 30, clientY: 30, which: 1 };
|
||||
var e2 = { clientX: 31, clientY: 31, which: 1 };
|
||||
var isClick = true;
|
||||
canvas.on('mouse:up', function(opt) {
|
||||
isClick = opt.isClick;
|
||||
});
|
||||
canvas.__onMouseDown(e);
|
||||
canvas.__onMouseMove(e2);
|
||||
canvas.__onMouseUp(e2);
|
||||
equal(isClick, false, 'moving the pointer, the click is false');
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue