|
|
@ -86,8 +86,8 @@ |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
_getEvents: function () { |
|
|
|
_getEvents: function () { |
|
|
|
if (!_.isArray(this.events)) { |
|
|
|
if (!_.isObject(this.events)) { |
|
|
|
this.events = []; |
|
|
|
this.events = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
return this.events; |
|
|
|
return this.events; |
|
|
|
}, |
|
|
|
}, |
|
|
@ -98,6 +98,7 @@ |
|
|
|
* @param {Function} fn 事件对应的执行函数 |
|
|
|
* @param {Function} fn 事件对应的执行函数 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
on: function (eventName, fn) { |
|
|
|
on: function (eventName, fn) { |
|
|
|
|
|
|
|
var self = this; |
|
|
|
eventName = eventName.toLowerCase(); |
|
|
|
eventName = eventName.toLowerCase(); |
|
|
|
var fns = this._getEvents()[eventName]; |
|
|
|
var fns = this._getEvents()[eventName]; |
|
|
|
if (!_.isArray(fns)) { |
|
|
|
if (!_.isArray(fns)) { |
|
|
@ -105,6 +106,10 @@ |
|
|
|
this._getEvents()[eventName] = fns; |
|
|
|
this._getEvents()[eventName] = fns; |
|
|
|
} |
|
|
|
} |
|
|
|
fns.push(fn); |
|
|
|
fns.push(fn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return function () { |
|
|
|
|
|
|
|
self.un(eventName, fn); |
|
|
|
|
|
|
|
}; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -148,7 +153,7 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
purgeListeners: function () { |
|
|
|
purgeListeners: function () { |
|
|
|
/* alex:清空events*/ |
|
|
|
/* alex:清空events*/ |
|
|
|
this.events = []; |
|
|
|
this.events = {}; |
|
|
|
}, |
|
|
|
}, |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 触发绑定过的事件 |
|
|
|
* 触发绑定过的事件 |
|
|
|