Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions cocos2d/core/event/event-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,22 @@ var proto = EventTarget.prototype;

proto._addEventFlag = function (type, listeners, useCapture) {
var cache = this._hasListenerCache;

if (!cache) {
cache = this._hasListenerCache = cc.js.createMap();
}

if (cache[type] === undefined) {
cache[type] = 0;
}

var flag = useCapture ? CAPTURING_FLAG : BUBBLING_FLAG;
cache[type] |= flag;
};

proto._purgeEventFlag = function (type, listeners, useCapture) {
var cache = this._hasListenerCache;

if (!cache || listeners.has(type)) {
return;
}
Expand All @@ -182,7 +182,7 @@ proto._resetFlagForTarget = function (target, listeners, useCapture) {
if (!cache) {
return;
}

var flag = useCapture ? CAPTURING_FLAG : BUBBLING_FLAG;
for (var key in cache) {
if (!listeners.has(key)) {
Expand Down Expand Up @@ -319,7 +319,7 @@ proto.off = function (type, callback, target, useCapture) {

this._purgeEventFlag(type, listeners, useCapture);
}

}
};

Expand Down Expand Up @@ -434,16 +434,24 @@ proto.emit = function (message, detail) {
event.eventPhase = 2;
event.target = event.currentTarget = this;

var res;
var capturingListeners = this._capturingListeners;
if (capturingListeners && (flag & CAPTURING_FLAG)) {
capturingListeners.invoke(event);
res = capturingListeners.invoke(event);
}
var bubblingListeners = this._bubblingListeners;
if (bubblingListeners && (flag & BUBBLING_FLAG) && !event._propagationImmediateStopped) {
bubblingListeners.invoke(event);
res = bubblingListeners.invoke(event);
}
if (res && typeof res.finally === 'function') {
res.finally(function() {
event.detail = null;
cc.Event.EventCustom.put(event);
});
} else {
event.detail = null;
cc.Event.EventCustom.put(event);
}
event.detail = null;
cc.Event.EventCustom.put(event);
};

/*
Expand Down