Repository navigation
Expand file tree
/
Copy pathEventHandlerList.js
More file actions
59 lines (57 loc) · 2.39 KB
/
Copy pathEventHandlerList.js
File metadata and controls
59 lines (57 loc) · 2.39 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#if COPYRIGHT
//------------------------------------------------------------------------------
// <copyright file="EventHandlerList.js" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
#endif
Sys.EventHandlerList = function() {
/// <summary>The EventHandlerList class contains a dictionary of multicast events.</summary>
this._list = {};
}
Sys.EventHandlerList.prototype = {
_addHandler: function(id, handler) {
Array.add(this._getEvent(id, true), handler);
},
addHandler: function(id, handler) {
/// <summary>The addHandler method adds a handler to the event identified by id.</summary>
/// <param name="id" type="String">The identifier for the event.</param>
/// <param name="handler" type="Function">The handler to add to the event.</param>
this._addHandler(id, handler);
},
_removeHandler: function(id, handler) {
var evt = this._getEvent(id);
if (!evt) return;
Array.remove(evt, handler);
},
removeHandler: function(id, handler) {
/// <summary>The removeHandler method removes a handler to the event identified by id.</summary>
/// <param name="id" type="String">The identifier for the event.</param>
/// <param name="handler" type="Function">The handler to remove from the event.</param>
this._removeHandler(id, handler);
},
getHandler: function(id) {
/// <summary>
/// The getHandler method returns a single function that will call all
/// handlers sequentially for the specified event.
/// </summary>
/// <param name="id" type="String">The identifier for the event.</param>
/// <returns type="Function">A function that will call each handler sequentially.</returns>
var evt = this._getEvent(id);
if (!evt || (evt.length === 0)) return null;
evt = Array.clone(evt);
return function(source, args) {
for (var i = 0, l = evt.length; i < l; i++) {
evt[i](source, args);
}
};
},
_getEvent: function(id, create) {
if (!this._list[id]) {
if (!create) return null;
this._list[id] = [];
}
return this._list[id];
}
}
Sys.EventHandlerList.registerClass('Sys.EventHandlerList');