currentTarget fix

This commit is contained in:
Anton Lavrenov 2016-01-04 08:24:27 +08:00
parent 7f2315fb1d
commit 2e76cfba30
4 changed files with 16 additions and 11 deletions

View File

@ -3,7 +3,7 @@
* Konva JavaScript Framework v0.11.0
* http://konvajs.github.io/
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Sat Jan 02 2016
* Date: Mon Jan 04 2016
*
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
@ -3563,9 +3563,9 @@
* node.fire('click', null, true);
*/
fire: function(eventType, evt, bubble) {
evt = evt || {};
evt.target = evt.target || this;
// bubble
evt = Konva.Util.cloneObject(evt || {});
evt.currentTarget = this;
if (bubble) {
this._fireAndBubble(eventType, evt);
}
@ -4005,7 +4005,7 @@
// simulate event bubbling
var stopBubble = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && ((compareShape && compareShape.isAncestorOf && compareShape.isAncestorOf(this)) || !!(compareShape && compareShape.isAncestorOf));
if(evt && !evt.cancelBubble && this.parent && this.parent.isListening() && (!stopBubble)) {
if((evt && !evt.cancelBubble || !evt) && this.parent && this.parent.isListening() && (!stopBubble)) {
if(compareShape && compareShape.parent) {
this._fireAndBubble.call(this.parent, eventType, evt, compareShape.parent);
}
@ -4019,6 +4019,8 @@
var events = this.eventListeners[eventType],
i;
evt = Konva.Util.cloneObject(evt || {});
evt.currentTarget = this;
evt.type = eventType;
if (events) {

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1326,9 +1326,9 @@
* node.fire('click', null, true);
*/
fire: function(eventType, evt, bubble) {
evt = evt || {};
evt.target = evt.target || this;
// bubble
evt = Konva.Util.cloneObject(evt || {});
evt.currentTarget = this;
if (bubble) {
this._fireAndBubble(eventType, evt);
}
@ -1768,7 +1768,7 @@
// simulate event bubbling
var stopBubble = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && ((compareShape && compareShape.isAncestorOf && compareShape.isAncestorOf(this)) || !!(compareShape && compareShape.isAncestorOf));
if(evt && !evt.cancelBubble && this.parent && this.parent.isListening() && (!stopBubble)) {
if((evt && !evt.cancelBubble || !evt) && this.parent && this.parent.isListening() && (!stopBubble)) {
if(compareShape && compareShape.parent) {
this._fireAndBubble.call(this.parent, eventType, evt, compareShape.parent);
}
@ -1782,6 +1782,8 @@
var events = this.eventListeners[eventType],
i;
evt = Konva.Util.cloneObject(evt || {});
evt.currentTarget = this;
evt.type = eventType;
if (events) {

View File

@ -1899,12 +1899,13 @@ suite('Node', function() {
var fired = false;
layer.on('click', 'Circle', function(e) {
console.log(e);
assert.equal(this, circle);
assert.equal(e.currentTarget, circle);
fired = true;
});
circle.fire('click', null, true);
assert(fired, true);
assert.equal(fired, true);
});
test('complex event delegation', function() {
@ -1935,7 +1936,7 @@ suite('Node', function() {
fired = true;
});
circle.fire('click', null, true);
assert(fired, true);
assert.equal(fired, true);
});
// ======================================================
test('move shape, group, and layer, and then get absolute position', function() {