Skip to content

Commit

Permalink
Handle wheel event as a normal event with target. (#3612)
Browse files Browse the repository at this point in the history
* wheel event with target
* fix target detection
  • Loading branch information
asturur authored Jan 7, 2017
1 parent 4df8ef3 commit 920b83b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,6 @@
activeGroup = this.getActiveGroup(),
activeObject = this.getActiveObject(),
activeTarget;

// first check current group (if one exists)
// active group does not check sub targets like normal groups.
// if active group just exits.
Expand All @@ -1111,7 +1110,6 @@
}

this.targets = [];

var target = this._searchPossibleTargets(this._objects, pointer);
if (e[this.altSelectionKey] && target && activeTarget && target !== activeTarget) {
target = activeTarget;
Expand Down
11 changes: 4 additions & 7 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,9 @@
* @param {fabric.Object} targetObj receiving event
*/
_handleEvent: function(e, eventType, targetObj) {
var target = typeof targetObj === undefined ? this.findTarget(e) : targetObj,
var target = typeof targetObj === 'undefined' ? this.findTarget(e) : targetObj,
targets = this.targets || [],
options = { e: e, target: target, subTargets: targets };

this.fire('mouse:' + eventType, options);
target && target.fire('mouse' + eventType, options);
for (var i = 0; i < targets.length; i++) {
Expand Down Expand Up @@ -457,8 +456,7 @@
*/
__onMouseDown: function (e) {

var target = this.findTarget(e),
pointer = this.getPointer(e, true);
var target = this.findTarget(e);

// if right click just fire events
var isRightClick = 'which' in e ? e.which === 3 : e.button === 2;
Expand All @@ -480,6 +478,7 @@
}

// save pointer for check in __onMouseUp event
var pointer = this.getPointer(e, true);
this._previousPointer = pointer;

var shouldRender = this._shouldRender(target, pointer),
Expand Down Expand Up @@ -628,9 +627,7 @@
* @param {Event} e Event object fired on mouseup
*/
__onMouseWheel: function(e) {
this.fire('mouse:wheel', {
e: e
});
this._handleEvent(e, 'wheel');
},

/**
Expand Down
1 change: 1 addition & 0 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @fires mouseup
* @fires mouseover
* @fires mouseout
* @fires mousewheel
*/
fabric.Object = fabric.util.createClass(fabric.CommonMethods, /** @lends fabric.Object.prototype */ {

Expand Down

0 comments on commit 920b83b

Please sign in to comment.