X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/eb9b087b8088d289a759c263de54898a299800d1..3184781b2123ac21ed524a63248cdc07ef5dc668:/js/ui/baseui.js diff --git a/js/ui/baseui.js b/js/ui/baseui.js index e7ce49b..2845c2f 100644 --- a/js/ui/baseui.js +++ b/js/ui/baseui.js @@ -1,58 +1,47 @@ -WINDOW_STATUS = 1; -WINDOW_QUERY = 2; -WINDOW_CHANNEL = 3; +qwebirc.ui.WINDOW_STATUS = 1; +qwebirc.ui.WINDOW_QUERY = 2; +qwebirc.ui.WINDOW_CHANNEL = 3; +qwebirc.ui.WINDOW_CUSTOM = 4; +qwebirc.ui.WINDOW_CONNECT = 5; +qwebirc.ui.CUSTOM_CLIENT = "custom"; -var UIWindow = new Class({ - Implements: [Events], - initialize: function(parentObject, client, type, name, identifier) { - this.parentObject = parentObject; - this.type = type; - this.name = name; - this.active = false; - this.client = client; - this.identifier = identifier; +qwebirc.ui.BaseUI = new Class({ + Implements: [Events, Options], + options: { + appTitle: "QuakeNet Web IRC", + singleWindow: true }, - updateNickList: function(nicks) { - }, - updateTopic: function(topic) { - }, - close: function() { - this.parentObject.__closed(this); - this.fireEvent("close", this); - }, - select: function() { - this.active = true; - this.parentObject.__setActiveWindow(this); - }, - deselect: function() { - this.active = false; - }, - addLine: function(type, line, colour) { - }, - errorMessage: function(message) { - this.addLine("", message, "red"); - } -}); - -var UI = new Class({ - initialize: function(parentElement, windowClass, uiName) { + initialize: function(parentElement, windowClass, uiName, options) { + this.setOptions(options); + this.windows = {}; + this.windows[qwebirc.ui.CUSTOM_CLIENT] = {}; this.windowArray = []; this.windowClass = windowClass; this.parentElement = parentElement; this.parentElement.addClass("qwebirc"); this.parentElement.addClass("qwebirc-" + uiName); + this.firstClient = false; + this.commandhistory = new qwebirc.irc.CommandHistory(); }, newClient: function(client) { + client.hilightController = new qwebirc.ui.HilightController(client); + this.windows[client] = {} - var w = this.newWindow(client, WINDOW_STATUS, "Status"); + var w = this.newWindow(client, qwebirc.ui.WINDOW_STATUS, "Status"); this.selectWindow(w); - + if(!this.firstClient) { + this.firstClient = true; + w.addLine("", "qwebirc v" + qwebirc.VERSION); + w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved."); + w.addLine("", "http://webchat.quakenet.org/"); + w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org"); + } return w; }, newWindow: function(client, type, name) { var identifier = name; - if(type == WINDOW_STATUS) + if(type == qwebirc.ui.WINDOW_STATUS) identifier = ""; var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier); @@ -70,6 +59,30 @@ var UI = new Class({ if(this.active) this.active.deselect(); window.select(); /* calls setActiveWindow */ + document.title = window.name + " - " + this.options.appTitle; + }, + nextWindow: function(direction) { + if(this.windowArray.length == 0 || !this.active) + return; + + if(!direction) + direction = 1; + + var index = this.windowArray.indexOf(this.active); + if(index == -1) + return; + + index = index + direction; + if(index < 0) { + index = this.windowArray.length - 1; + } else if(index >= this.windowArray.length) { + index = 0; + } + + this.selectWindow(this.windowArray[index]); + }, + prevWindow: function() { + this.nextWindow(-1); }, __closed: function(window) { if(window.active) { @@ -78,37 +91,154 @@ var UI = new Class({ this.windowArray = []; } else { var index = this.windowArray.indexOf(window); - if(index == 0) { + if(index == -1) { + return; + } else if(index == 0) { this.selectWindow(this.windowArray[1]); } else { this.selectWindow(this.windowArray[index - 1]); } - - this.windowArray = this.windowArray.erase(window); } } + this.windowArray = this.windowArray.erase(window); delete this.windows[window.client][window.identifier]; }, - loginBox: function(callback) { /* this shouldn't be called by overriding classes! + they should implement their own! some form of user input MUST be received before an IRC connection is made, else users are going to get tricked into getting themselves glined */ + loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) { + qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick); + } +}); + +qwebirc.ui.StandardUI = new Class({ + Extends: qwebirc.ui.BaseUI, + initialize: function(parentElement, windowClass, uiName, options) { + this.parent(parentElement, windowClass, uiName, options); + + this.tabCompleter = new qwebirc.ui.TabCompleterFactory(this); - var nick = prompt("Nickname:"); - if(!nick) { - alert("Aborted."); + window.addEvent("keydown", function(x) { + if(!x.alt || x.control) + return; + + var success = false; + if(x.key == "a" || x.key == "A") { + var highestNum = 0; + var highestIndex = -1; + success = true; + + new Event(x).stop(); + for(var i=0;i highestNum) { + highestIndex = i; + highestNum = h; + } + } + if(highestIndex > -1) + this.selectWindow(this.windowArray[highestIndex]); + } else if(x.key >= '0' && x.key <= '9') { + success = true; + + number = x.key - '0'; + if(number == 0) + number = 10 + + number = number - 1; + + if(number >= this.windowArray.length) + return; + + this.selectWindow(this.windowArray[number]); + } else if(x.key == "left") { + this.prevWindow(); + success = true; + } else if(x.key == "right") { + this.nextWindow(); + success = true; + } + if(success) + new Event(x).stop(); + }.bind(this)); + }, + newCustomWindow: function(name, select, type) { + if(!type) + type = qwebirc.ui.WINDOW_CUSTOM; + + var w = this.newWindow(qwebirc.ui.CUSTOM_CLIENT, type, name); + w.addEvent("close", function(w) { + delete this.windows[name]; + }.bind(this)); + + if(select) + this.selectWindow(w); + + return w; + }, + embeddedWindow: function() { + if(this.embedded) { + this.selectWindow(this.embedded) return; } + + this.embedded = this.newCustomWindow("Embedding wizard", true); + this.embedded.addEvent("close", function() { + this.embedded = null; + }.bind(this)); + + var ew = new qwebirc.ui.EmbedWizard({parent: this.embedded.lines}); + ew.addEvent("close", function() { + this.embedded.close(); + }.bind(this)); + }, + urlDispatcher: function(name) { + if(name == "embedded") + return ["a", this.embeddedWindow.bind(this)]; + + return null; + }, + tabComplete: function(element) { + this.tabCompleter.tabComplete(element); + }, + resetTabComplete: function() { + this.tabCompleter.reset(); + } +}); - var chans = prompt("Channels (seperate by comma):", "#quakenetX"); - if(chans) { - callback(nick, chans); - } else { - callback(nick); +qwebirc.ui.QuakeNetUI = new Class({ + Extends: qwebirc.ui.StandardUI, + urlDispatcher: function(name, window) { + if(name == "qwhois") { + return ["a", function(auth) { + this.client.exec("/MSG Q whois #" + auth); + }.bind(window)]; } + if(name == "whois") { + return ["span", function(nick) { + this.client.exec("/WHOIS " + nick); + }.bind(window)]; + } + + return this.parent(name); + } +}); + +qwebirc.ui.NewLoginUI = new Class({ + Extends: qwebirc.ui.QuakeNetUI, + loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) { + this.postInitialize(); + var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT); + var callback = function(args) { + w.close(); + callbackfn(args); + }; + + qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick); } });