blob: 7172609250843a4a59743e1beebe45ec51c56f74 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/*==================================================
* General, miscellaneous SimileAjax stuff
*==================================================
*/
SimileAjax.ListenerQueue = function(wildcardHandlerName) {
this._listeners = [];
this._wildcardHandlerName = wildcardHandlerName;
};
SimileAjax.ListenerQueue.prototype.add = function(listener) {
this._listeners.push(listener);
};
SimileAjax.ListenerQueue.prototype.remove = function(listener) {
var listeners = this._listeners;
for (var i = 0; i < listeners.length; i++) {
if (listeners[i] == listener) {
listeners.splice(i, 1);
break;
}
}
};
SimileAjax.ListenerQueue.prototype.fire = function(handlerName, args) {
var listeners = [].concat(this._listeners);
for (var i = 0; i < listeners.length; i++) {
var listener = listeners[i];
if (handlerName in listener) {
try {
listener[handlerName].apply(listener, args);
} catch (e) {
SimileAjax.Debug.exception("Error firing event of name " + handlerName, e);
}
} else if (this._wildcardHandlerName != null &&
this._wildcardHandlerName in listener) {
try {
listener[this._wildcardHandlerName].apply(listener, [ handlerName ]);
} catch (e) {
SimileAjax.Debug.exception("Error firing event of name " + handlerName + " to wildcard handler", e);
}
}
}
};
|