#if COPYRIGHT //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //------------------------------------------------------------------------------ #endif Sys.EventHandlerList = function() { /// The EventHandlerList class contains a dictionary of multicast events. this._list = {}; } Sys.EventHandlerList.prototype = { _addHandler: function(id, handler) { Array.add(this._getEvent(id, true), handler); }, addHandler: function(id, handler) { /// The addHandler method adds a handler to the event identified by id. /// The identifier for the event. /// The handler to add to the event. this._addHandler(id, handler); }, _removeHandler: function(id, handler) { var evt = this._getEvent(id); if (!evt) return; Array.remove(evt, handler); }, removeHandler: function(id, handler) { /// The removeHandler method removes a handler to the event identified by id. /// The identifier for the event. /// The handler to remove from the event. this._removeHandler(id, handler); }, getHandler: function(id) { /// /// The getHandler method returns a single function that will call all /// handlers sequentially for the specified event. /// /// The identifier for the event. /// A function that will call each handler sequentially. 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');