TCPConnection now IRCConnection and is built using Mootools.
Fix for IE.
return true;\r
}\r
\r
- this.connection = new TCPConnection(nickname, this);\r
- this.send = this.connection.send;\r
- this.connect = this.connection.connect;\r
+ this.connection = new IRCConnection({initialNickname: nickname, onRecv: this.dispatch});\r
+ \r
+ this.send = this.connection.send.bind(this.connection);\r
+ this.connect = this.connection.connect.bind(this.connection);\r
this.disconnect = this.connection.disconnect;\r
}\r
message = "";\r
\r
send("KICK " + channel + " " + target + " :" + message);\r
- }],\r
+ }]\r
};\r
\r
this.dispatch = function(line) {\r
this.__send = this.parent.send;\r
\r
this.commandparser = new CommandParser(this);\r
- this.dispatch = this.commandparser.dispatch\r
+ this.dispatch = this.commandparser.dispatch;\r
\r
this.statusWindow = ui.newClient(self);\r
\r
-function TCPConnection(nickname, parser) {\r
- var self = this;\r
- var dispatch = parser.dispatch;\r
- var counter = 0;\r
- var disconnected = false;\r
- \r
- this.send = function(data) {\r
- XHR("/e/p/" + self.sessionid + "?c=" + encodeURIComponent(data) + "&t=" + counter++, function(o) {\r
+var IRCConnection = new Class({\r
+ Implements: [Events, Options],\r
+ options: {\r
+ initialNickname: "ircconnX"\r
+ },\r
+ initialize: function(options) {\r
+ this.setOptions(options);\r
+ \r
+ this.initialNickname = this.options.initialNickname;\r
+ \r
+ this.counter = 0;\r
+ this.disconnected = false;\r
+ },\r
+ send: function(data) {\r
+ var r = new Request.JSON({url: "/e/p/" + this.sessionid + "?c=" + encodeURIComponent(data) + "&t=" + this.counter++, onComplete: function(o) {\r
if(o[0] == false)\r
alert("An error occured: " + o[1]);\r
- });\r
- }\r
-\r
- this.recv = function() {\r
- if(self.disconnected)\r
+ }});\r
+ \r
+ r.get();\r
+ },\r
+ x: function() {\r
+ this.fireEvent("recv", [[false, "moo"]]);\r
+ },\r
+ recv: function() {\r
+ if(this.disconnected)\r
return;\r
\r
- XHR("/e/s/" + self.sessionid + "?t=" + counter++, function(o) {\r
+ var r = new Request.JSON({url: "/e/s/" + this.sessionid + "?t=" + this.counter++, onComplete: function(o) {\r
if(o[0] == false) {\r
alert("An error occured: " + o[1]);\r
return;\r
}\r
- forEach(o, function(x) {\r
- dispatch(x);\r
- });\r
- self.recv();\r
- });\r
- }\r
-\r
- this.connect = function() {\r
- XHR("/e/n?nick=" + encodeURIComponent(nickname) + "&r=" + Math.random() * 1024 * 1024, function(o) {\r
+ o.each(function(x) {\r
+ this.fireEvent("recv", [x]);\r
+ }, this);\r
+ \r
+ this.recv();\r
+ }.bind(this)}); \r
+ r.get();\r
+ },\r
+ connect: function() {\r
+ var r = new Request.JSON({url: "/e/n?nick=" + encodeURIComponent(this.initialNickname) + "&r=" + Math.random() * 1024 * 1024, onComplete: function(o) {\r
if(o[0] == false) {\r
alert("An error occured: " + o[1]);\r
return;\r
}\r
- self.sessionid = o[1];\r
- self.recv(); \r
- });\r
- }\r
- \r
- this.disconnect = function() {\r
- self.disconnected = true;\r
+ this.sessionid = o[1];\r
+ \r
+ this.recv(); \r
+ }.bind(this)});\r
+ r.get();\r
+ },\r
+ disconnect: function() {\r
+ this.disconnected = true;\r
}\r
-}
\ No newline at end of file
+});\r
line = this.parentObject.theme.message(type, line);\r
\r
colourise(timestamp() + " " + line, e);\r
- this.lines.appendChild(e);\r
\r
this.lastcolour = !this.lastcolour;\r
+ \r
+ var prev = this.lines.getScroll();\r
+ var prevbottom = this.lines.getScrollSize().y;\r
+ var prevsize = this.lines.getSize();\r
+ this.lines.appendChild(e);\r
+ \r
+ if(prev.y + prevsize.y == prevbottom)\r
+ this.lines.scrollTo(prev.x, this.lines.getScrollSize().y);\r
+ \r
+ if(!this.active)\r
+ this.tab.setStyle("color", "red");\r
}\r
});\r
\r
parentElement.appendChild(form); \r
form.appendChild(inputbox);\r
inputbox.focus();\r
- },\r
+ }\r
});
\ No newline at end of file
WINDOW_CHANNEL = 3;\r
\r
var UIWindow = new Class({\r
+ Implements: [Events],\r
initialize: function(parentObject, client, type, name, identifier) {\r
this.parentObject = parentObject;\r
this.type = type;\r
this.addLine("", message, "red");\r
}\r
});\r
-UIWindow.implement(new Events);\r
\r
var UI = new Class({\r
initialize: function(windowClass) {\r
if(type == WINDOW_STATUS)\r
identifier = "";\r
\r
- w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);\r
+ var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);\r
this.windowArray.push(w);\r
\r
return w;\r
__closed: function(window) {\r
if(window.active) {\r
this.active = undefined;\r
- if(this.windowArray.length > 1) {\r
- for(var i=0;i<this.windowArray.length;i++) {\r
- if(this.windowArray[i] != window)\r
- continue;\r
-\r
- if(i == 0) {\r
- this.selectWindow(this.windowArray[1]);\r
- } else {\r
- this.selectWindow(this.windowArray[i - 1]);\r
- }\r
- this.windowArray = this.windowArray.splice(i, 1);\r
- break;\r
+ if(this.windowArray.length == 1) {\r
+ this.windowArray = [];\r
+ } else {\r
+ var index = this.windowArray.indexOf(window);\r
+ if(i == 0) {\r
+ this.selectWindow(this.windowArray[1]);\r
+ } else {\r
+ this.selectWindow(this.windowArray[index - 1]);\r
}\r
+ \r
+ this.windowArray = this.windowArray.erase(window);\r
}\r
}\r
\r