Author: damoxc
Revision: 5120
Log:
extend Ext.util.Observable rather than reinventing
Diff:
Modified: trunk/deluge/ui/web/js/Deluge.Events.js
===================================================================
--- trunk/deluge/ui/web/js/Deluge.Events.js 2009-04-21 20:15:49 UTC (rev
5119)
+++ trunk/deluge/ui/web/js/Deluge.Events.js 2009-04-21 20:27:25 UTC (rev
5120)
@@ -18,66 +18,24 @@
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
- **
+ *
* @class Deluge.Events
* <p>Class for holding global events that occur within the UI.</p>
* @singleton
*/
-Deluge.Events = {
-
- // private
- __events: {},
-
- /**
- * Fires an event, calling any listening event handlers and passing the
- * given arguments.
- * @param {String} name The name of the event to call.
- * @param eventArg1 (optional)
- * @param eventArg2 (optional)...
- */
- fire: function() {
- var args = [];
- Ext.each(arguments, function(arg) {
- args.push(arg);
- });
-
- var eventName = args.shift();
- if (!this.__events[eventName]) return;
-
- var eventArgs = arguments;
- Ext.each(this.__events[eventName], function(cb) {
- try {
- cb.fn.apply(cb.scope || this, eventArgs);
- } catch (e) {
- alert(e);
- }
- });
- },
-
- /**
- * Attachs an event listener.
- *
- */
- on: function(eventName, fn, scope) {
- var e = this.__events[eventName] || new Array();
- e.push({
- 'fn': fn,
- 'scope': scope
- });
- this.__events[eventName] = e;
- },
-
- /**
- * Removes an event listener.
- */
- removeListener: function(eventName, fn) {
- if (!this.__events[eventName]) return;
- this.__events[eventName].remove(fn);
- },
-
- /**
- * Alias to removeListener
- *
- */
- un: this.removeListener
-};
\ No newline at end of file
+
+(function() {
+ Events = Ext.extend(Ext.util.Observable, {
+ constructor: function() {
+ Events.superclass.constructor.call(this);
+ },
+
+ addListener: function(eventName, fn, scope, o) {
+ this.addEvents(eventName);
+ Events.superclass.addListener.call(this, eventName, fn, scope, o);
+ }
+ });
+ Events.prototype.on = Events.prototype.addListener
+ Events.prototype.fire = Events.prototype.fireEvent
+ Deluge.Events = new Events();
+})();
\ No newline at end of file
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---