Merge pull request #1796 from pandamicro/master

Allow to off all listeners for a type and small fixes
This commit is contained in:
Wang Nan
2017-07-11 09:45:58 +08:00
committed by GitHub
4 changed files with 20 additions and 14 deletions
+16 -10
View File
@@ -205,13 +205,14 @@ proto.on = function (type, callback, target, useCapture) {
/**
* !#en
* Removes the callback previously registered with the same type, callback, target and or useCapture.
* Removes the listeners previously registered with the same type, callback, target and or useCapture,
* if only type is passed as parameter, all listeners registered with that type will be removed.
* !#zh
* 删除之前与同类型,回调,目标或 useCapture 注册的回调。
* 删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。
*
* @method off
* @param {String} type - A string representing the event type being removed.
* @param {Function} callback - The callback to remove.
* @param {Function} [callback] - The callback to remove.
* @param {Object} [target] - The target to invoke the callback, if it's not given, only callback without target will be removed
* @param {Boolean} [useCapture=false] - Specifies whether the callback being removed was registered as a capturing callback or not.
* If not specified, useCapture defaults to false. If a callback was registered twice,
@@ -222,8 +223,10 @@ proto.on = function (type, callback, target, useCapture) {
* var touchEnd = node.on(cc.Node.EventType.TOUCH_END, function (event) {
* cc.log("this is callback");
* }, node);
* // remove touchEnd eventListener
* // remove touch end event listener
* node.off(cc.Node.EventType.TOUCH_END, touchEnd, node);
* // remove all touch end event listeners
* node.off(cc.Node.EventType.TOUCH_END);
*/
proto.off = function (type, callback, target, useCapture) {
// Accept also patameters like: (type, callback, useCapture)
@@ -233,14 +236,17 @@ proto.off = function (type, callback, target, useCapture) {
}
else useCapture = !!useCapture;
if (!callback) {
return;
this._capturingListeners && this._capturingListeners.removeAll(type);
this._bubblingListeners && this._bubblingListeners.removeAll(type);
}
var listeners = useCapture ? this._capturingListeners : this._bubblingListeners;
if (listeners) {
listeners.remove(type, callback, target);
else {
var listeners = useCapture ? this._capturingListeners : this._bubblingListeners;
if (listeners) {
listeners.remove(type, callback, target);
if (target && target.__eventTargets) {
fastRemove(target.__eventTargets, this);
if (target && target.__eventTargets) {
fastRemove(target.__eventTargets, this);
}
}
}
};
+1 -1
View File
@@ -320,7 +320,7 @@ var Graphics = cc.Class({
* @param {Boolean} [clean] Whether to clean the graphics inner cache.
*/
clear: function (clean) {
this._sgNode.clear(clean);
this._sgNode.clear(!!clean);
},
/**
+1 -1
View File
@@ -563,7 +563,7 @@ else {
else if (nav.appVersion.indexOf("Mac") !== -1) osName = sys.OS_OSX;
else if (nav.appVersion.indexOf("X11") !== -1 && nav.appVersion.indexOf("Linux") === -1) osName = sys.OS_UNIX;
else if (isAndroid) osName = sys.OS_ANDROID;
else if (nav.appVersion.indexOf("Linux") !== -1) osName = sys.OS_LINUX;
else if (nav.appVersion.indexOf("Linux") !== -1 || ua.indexOf("ubuntu") !== -1) osName = sys.OS_LINUX;
/**
* Indicate the running os name
+2 -2
View File
@@ -124,8 +124,8 @@ misc.imagePool.get = function () {
return this._get() || new Image();
};
misc.imagePool._smallImg = "data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=";
// Avoid problems on windows IE kernels, Edge, Firefox
if (sys.os === sys.OS_WINDOWS && sys.browser !== sys.BROWSER_TYPE_CHROME) {
// Avoid problems on windows IE kernels, Edge, Firefox and Linux Firefox
if ((sys.os === sys.OS_WINDOWS || sys.os === sys.OS_LINUX) && sys.browser !== sys.BROWSER_TYPE_CHROME) {
misc.imagePool.resize(0);
}