+
+qwebirc.ui.StandardUI = new Class({
+ Extends: qwebirc.ui.BaseUI,
+ UICommands: qwebirc.ui.UI_COMMANDS,
+ initialize: function(parentElement, windowClass, uiName, options) {
+ this.parent(parentElement, windowClass, uiName, options);
+
+ this.__styleValues = {hue: qwebirc.ui.DEFAULT_HUE, saturation: 0, lightness: 0, textHue: null, textSaturation: null, textLightness: null};
+ if($defined(this.options.hue)) this.__styleValues.hue = this.options.hue;
+ this.tabCompleter = new qwebirc.ui.TabCompleterFactory(this);
+ this.uiOptions = new qwebirc.ui.DefaultOptionsClass(this, options.uiOptionsArg);
+ this.customWindows = new QHash();
+
+ if($defined(this.options.saturation)) this.__styleValues.saturation = this.options.saturation;
+ if($defined(this.options.lightness)) this.__styleValues.lightness = this.options.lightness;
+ if($defined(this.options.tsaturation)) this.__styleValues.textSaturation = this.options.tsaturation;
+ if($defined(this.options.tlightness)) this.__styleValues.textLightness = this.options.tlightness;
+
+ if($defined(this.options.hue)) { /* overridden in url */
+ /* ugh... this will go away when we add proper options for hue/sat/light for text and background */
+ this.uiOptions.setValueByPrefix("STYLE_HUE", this.__styleValues.hue);
+ } else {
+ this.__styleValues.hue = this.uiOptions.STYLE_HUE; /* otherwise copy from serialised store */
+ }
+ this.__styleValues.textHue = $defined(this.options.thue) ? this.options.thue : this.__styleValues.hue;
+
+ document.addEvent("keydown", this.__handleHotkey.bind(this));
+ },
+ __handleHotkey: function(x) {
+ var success = false;
+ if(!x.alt && !x.control && !x.shift && !x.meta) {
+ if((x.key == "backspace" || x.key == "/") && !this.getInputFocused(x)) {
+ success = true;
+ }
+ } else if(!x.alt || x.control || x.meta) {
+ /* do nothing */
+ } else if(x.key == "a" || x.key == "A") {
+ var highestNum = 0;
+ var highestIndex = -1;
+ success = true;
+
+ for(var i=0;i<this.windowArray.length;i++) {
+ var h = this.windowArray[i].hilighted;
+ if(h > highestNum) {
+ highestIndex = i;
+ highestNum = h;
+ }
+ }
+ if(highestIndex > -1)
+ this.selectWindow(this.windowArray[highestIndex]);
+ } else if((x.key >= '0' && x.key <= '9') && !x.shift) {
+ 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" || x.key == "up") && !x.shift) {
+ this.prevWindow();
+ success = true;
+ } else if((x.key == "right" || x.key == "down") && !x.shift) {
+ this.nextWindow();
+ success = true;
+ }
+
+ if(success) {
+ new Event(x).stop();
+ x.preventDefault();
+ }
+ },
+ getInputFocused: function(x) {
+ if($$("input").indexOf(x.target) == -1 && $$("textarea").indexOf(x.target) == -1)
+ return false;
+ return true;
+ },
+ 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) {
+ this.windows.get(qwebirc.ui.CUSTOM_CLIENT).remove(w.identifier);
+ }.bind(this));
+
+ if(select)
+ this.selectWindow(w);
+
+ return w;
+ },
+ addCustomWindow: function(windowName, class_, cssClass, options) {
+ if(!$defined(options))
+ options = {};
+
+ if(this.customWindows.contains(windowName)) {
+ this.selectWindow(this.customWindows.get(windowName));
+ return;
+ }
+
+ var d = this.newCustomWindow(windowName, true);
+ this.customWindows.put(windowName, d);
+
+ d.addEvent("close", function() {
+ this.customWindows.remove(windowName);
+ }.bind(this));
+
+ if(cssClass)
+ d.lines.addClass("qwebirc-" + cssClass);
+
+ var ew = new class_(d.lines, options);
+ ew.addEvent("close", function() {
+ d.close();
+ }.bind(this));
+
+ d.setSubWindow(ew);
+ },
+ embeddedWindow: function() {
+ this.addCustomWindow("Add webchat to your site", qwebirc.ui.EmbedWizard, "embeddedwizard", {baseURL: this.options.baseURL, uiOptions: this.uiOptions, optionsCallback: function() {
+ this.optionsWindow();
+ }.bind(this)});
+ },
+ optionsWindow: function() {
+ this.addCustomWindow("Options", qwebirc.ui.OptionsPane, "optionspane", this.uiOptions);
+ },
+ aboutWindow: function() {
+ this.addCustomWindow("About", qwebirc.ui.AboutPane, "aboutpane", this.uiOptions);
+ },
+ privacyWindow: function() {
+ this.addCustomWindow("Privacy policy", qwebirc.ui.PrivacyPolicyPane, "privacypolicypane", this.uiOptions);
+ },
+ feedbackWindow: function() {
+ this.addCustomWindow("Feedback", qwebirc.ui.FeedbackPane, "feedbackpane", this.uiOptions);
+ },
+ helpWindow: function() {
+ this.addCustomWindow("Help!", qwebirc.ui.HelpPane, "helppane", this.uiOptions);
+ },
+ urlDispatcher: function(name, window) {
+ if(name == "embedded")
+ return ["a", this.embeddedWindow.bind(this)];
+
+ if(name == "options")
+ return ["a", this.optionsWindow.bind(this)];
+
+ /* doesn't really belong here */
+ if(name == "whois") {
+ return ["span", function(nick) {
+ if(this.uiOptions.QUERY_ON_NICK_CLICK) {
+ window.client.exec("/QUERY " + nick);
+ } else {
+ window.client.exec("/WHOIS " + nick);
+ }
+ }.bind(this)];
+ }
+
+ return null;
+ },
+ tabComplete: function(element, backwards) {
+ this.tabCompleter.tabComplete(element, backwards);
+ },
+ resetTabComplete: function() {
+ this.tabCompleter.reset();
+ },
+ setModifiableStylesheet: function(name) {
+ this.__styleSheet = new qwebirc.ui.style.ModifiableStylesheet(qwebirc.global.staticBaseURL + "css/" + name + qwebirc.FILE_SUFFIX + ".mcss");
+ this.setModifiableStylesheetValues({});
+ },
+ setModifiableStylesheetValues: function(values) {
+ for (var k in values)
+ this.__styleValues[k] = values[k];
+
+ if (!$defined(this.__styleSheet))
+ return;
+
+ var back = {hue: this.__styleValues.hue, lightness: this.__styleValues.lightness, saturation: this.__styleValues.saturation};
+ var front;
+ if (!$defined(this.__styleValues.textHue) && !$defined(this.__styleValues.textLightness) && !$defined(this.__styleValues.textSaturation)) {
+ front = back;
+ } else {
+ front = {hue: Number(this.__styleValues.textHue), lightness: Number(this.__styleValues.textLightness), saturation: Number(this.__styleValues.textSaturation)}
+ }
+ var colours = {
+ back: back,
+ front: front
+ };
+
+ this.__styleSheet.set(function() {
+ var mode = arguments[0];
+ if(mode == "c") {
+ var t = colours[arguments[2]];
+ var x = new Color(arguments[1]);
+ var c = x.setHue(t.hue).setSaturation(x.hsb[1] + t.saturation).setBrightness(x.hsb[2] + t.lightness);
+ if(c == "255,255,255") /* IE confuses white with transparent... */
+ c = "255,255,254";
+
+ return "rgb(" + c + ")";
+ } else if(mode == "o") {
+ return this.uiOptions[arguments[1]] ? arguments[2] : arguments[3];
+ }
+ }.bind(this));
+ }
+});
+
+qwebirc.ui.NotificationUI = new Class({
+ Extends: qwebirc.ui.StandardUI,
+ initialize: function(parentElement, windowClass, uiName, options) {
+ this.parent(parentElement, windowClass, uiName, options);
+
+ this.__beeper = new qwebirc.ui.Beeper(this.uiOptions);
+ this.__flasher = new qwebirc.ui.Flasher(this.uiOptions);
+ this.__notifier = new qwebirc.ui.Notifier(this.uiOptions);
+
+ this.cancelFlash = this.__flasher.cancelFlash.bind(this.__flasher);
+ },
+ beep: function() {
+ this.__beeper.beep();
+ },
+ notify: function(title, message, callback) {
+ this.__beeper.beep();
+ this.__flasher.flash();
+ this.__notifier.notify(title, message, callback);
+ },
+ setBeepOnMention: function(value) {
+ if(value)
+ this.__beeper.soundInit();
+ },
+ setNotifications: function(value) {
+ this.__notifier.setEnabled(value);
+ },
+ updateTitle: function(text) {
+ if(this.__flasher.updateTitle(text))
+ this.parent(text);
+ },
+ focusChange: function(value) {
+ this.parent(value);
+ this.__flasher.focusChange(value);
+ this.__notifier.focusChange(value);
+ }
+});
+
+qwebirc.ui.NewLoginUI = new Class({
+ Extends: qwebirc.ui.NotificationUI,
+ loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) {
+ this.postInitialize();
+
+ /* I'd prefer something shorter and snappier! */
+ 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, this.options.networkName);
+ }
+});
+
+qwebirc.ui.QuakeNetUI = new Class({
+ Extends: qwebirc.ui.NewLoginUI,
+ urlDispatcher: function(name, window) {
+ if(name == "qwhois") {
+ return ["span", function(auth) {
+ this.client.exec("/MSG Q whois #" + auth);
+ }.bind(window)];
+ }
+ return this.parent(name, window);
+ },
+ logout: function() {
+ if(!qwebirc.auth.loggedin())
+ return;
+ if(confirm("Log out?")) {
+ this.clients.each(function(k, v) {
+ v.quit("Logged out");
+ }, this);
+
+ /* HACK */
+ var foo = function() { document.location = qwebirc.global.dynamicBaseURL + "auth?logout=1"; };
+ foo.delay(500);
+ }
+ }
+});
+
+qwebirc.ui.RootUI = qwebirc.ui.QuakeNetUI;
+
+qwebirc.ui.RequestTransformHTML = function(options) {
+ var HREF_ELEMENTS = {
+ "IMG": 1
+ };
+
+ var update = options.update;
+ var onSuccess = options.onSuccess;
+
+ var fixUp = function(node) {
+ if(node.nodeType != 1)
+ return;
+
+ var tagName = node.nodeName.toUpperCase();
+ if(HREF_ELEMENTS[tagName]) {
+ var attr = node.getAttribute("transform_attr");
+ var value = node.getAttribute("transform_value");
+ if($defined(attr) && $defined(value)) {
+ node.removeAttribute("transform_attr");
+ node.removeAttribute("transform_value");
+ node.setAttribute(attr, qwebirc.global.staticBaseURL + value);
+ }
+ }
+
+ for(var i=0;i<node.childNodes.length;i++)
+ fixUp(node.childNodes[i]);
+ };
+
+ delete options["update"];
+ options.onSuccess = function(tree, elements, html, js) {
+ var container = new Element("div");
+ container.set("html", html);
+ fixUp(container);
+ update.empty();
+
+ while(container.childNodes.length > 0) {
+ var x = container.firstChild;
+ container.removeChild(x);
+ update.appendChild(x);
+ }
+ onSuccess();
+ };
+
+ return new Request.HTML(options);
+};
+