move over to central event holder

This commit is contained in:
Damien Churchill 2009-02-19 18:59:14 +00:00
parent b4cc833044
commit 5153ad6f78
4 changed files with 29 additions and 23 deletions

View File

@ -69,7 +69,7 @@ Deluge.ToolBar = {
}, },
onToolbarRender: function(toolbar) { onToolbarRender: function(toolbar) {
Deluge.Connections.on("connect", this.onConnect.bindWithEvent(this)); Deluge.Events.on("connect", this.onConnect.bindWithEvent(this));
} }
} }

View File

@ -1,5 +1,4 @@
Deluge.Connections = { Deluge.Connections = {
_events: new Hash(),
onClose: function(e) { onClose: function(e) {
$clear(Deluge.Connections.running); $clear(Deluge.Connections.running);
@ -16,7 +15,7 @@ Deluge.Connections = {
Deluge.Client = new JSON.RPC('/json', { Deluge.Client = new JSON.RPC('/json', {
methods: methods methods: methods
}); });
Deluge.Connections.fire("connect"); Deluge.Events.fire("connect");
} }
}); });
}, },
@ -36,24 +35,6 @@ Deluge.Connections = {
Deluge.Connections.runCheck(); Deluge.Connections.runCheck();
}, },
fire: function(eventName) {
if (!this._events[eventName]) return;
$each(this._events[eventName], function(fn) {
fn(Deluge.Client);
});
},
on: function(eventName, fn) {
var e = $pick(this._events[eventName], new Array());
e.include(fn);
this._events[eventName] = e;
},
removeListener: function(eventName, fn) {
if (!this._events[eventName]) return;
this._events[eventName].remove(fn);
},
runCheck: function() { runCheck: function() {
Deluge.Client.web.get_hosts({ Deluge.Client.web.get_hosts({
onSuccess: Deluge.Connections.onGetHosts onSuccess: Deluge.Connections.onGetHosts

View File

@ -17,7 +17,7 @@ Deluge.Ui = {
}); });
Deluge.Login.Window.show(); Deluge.Login.Window.show();
Deluge.Connections.on("connect", this.onConnect.bindWithEvent(this)); Deluge.Events.on("connect", this.onConnect.bindWithEvent(this));
Deluge.Client = new JSON.RPC('/json'); Deluge.Client = new JSON.RPC('/json');
Deluge.SideBar = this.MainPanel.items.get('sidebar'); Deluge.SideBar = this.MainPanel.items.get('sidebar');

View File

@ -1,4 +1,29 @@
var Deluge = $empty; var Deluge = {
author: 'Damien Churchill <damoxc@gmail.com>',
version: '1.2-dev'
};
Deluge.Events = {
_events: new Hash(),
fire: function(eventName) {
if (!this._events[eventName]) return;
$each(this._events[eventName], function(fn) {
fn(Deluge.Client);
});
},
on: function(eventName, fn) {
var e = $pick(this._events[eventName], new Array());
e.include(fn);
this._events[eventName] = e;
},
removeListener: function(eventName, fn) {
if (!this._events[eventName]) return;
this._events[eventName].remove(fn);
}
};
Deluge.Formatters = { Deluge.Formatters = {
size: function(bytes) { size: function(bytes) {