|
|
@ -3,6 +3,14 @@ function eventManager () { |
|
|
|
this.registered = {}; |
|
|
|
this.registered = {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
* Unregister a listenner. |
|
|
|
|
|
|
|
* Note that if obj is a function. the unregistration will be applied to the dummy obj {}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {String} eventName - the event name |
|
|
|
|
|
|
|
* @param {Object or Func} obj - object that will listen on this event |
|
|
|
|
|
|
|
* @param {Func} func - function of the listenners that will be executed |
|
|
|
|
|
|
|
*/ |
|
|
|
eventManager.prototype.unregister = function (eventName, obj, func) { |
|
|
|
eventManager.prototype.unregister = function (eventName, obj, func) { |
|
|
|
if (obj instanceof Function) { |
|
|
|
if (obj instanceof Function) { |
|
|
|
func = obj; |
|
|
|
func = obj; |
|
|
@ -17,6 +25,14 @@ eventManager.prototype.unregister = function (eventName, obj, func) { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
* Register a new listenner. |
|
|
|
|
|
|
|
* Note that if obj is a function, the function registration will be associated with the dummy object {} |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {String} eventName - the event name |
|
|
|
|
|
|
|
* @param {Object or Func} obj - object that will listen on this event |
|
|
|
|
|
|
|
* @param {Func} func - function of the listenners that will be executed |
|
|
|
|
|
|
|
*/ |
|
|
|
eventManager.prototype.register = function (eventName, obj, func) { |
|
|
|
eventManager.prototype.register = function (eventName, obj, func) { |
|
|
|
if (!this.registered[eventName]) { |
|
|
|
if (!this.registered[eventName]) { |
|
|
|
this.registered[eventName] = []; |
|
|
|
this.registered[eventName] = []; |
|
|
@ -31,6 +47,13 @@ eventManager.prototype.register = function (eventName, obj, func) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
* trigger event. |
|
|
|
|
|
|
|
* Every listenner have their associated function executed |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {String} eventName - the event name |
|
|
|
|
|
|
|
* @param {Array}j - argument that will be passed to the exectued function. |
|
|
|
|
|
|
|
*/ |
|
|
|
eventManager.prototype.trigger = function (eventName, args) { |
|
|
|
eventManager.prototype.trigger = function (eventName, args) { |
|
|
|
for (var listener in this.registered[eventName]) { |
|
|
|
for (var listener in this.registered[eventName]) { |
|
|
|
var l = this.registered[eventName][listener]; |
|
|
|
var l = this.registered[eventName][listener]; |
|
|
|