X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/c0f2f36718c47c1e61645ea3c20b641428de0899..77e5d85fa0f84ddcc89b36771eec58999e497e55:/js/qwebircinterface.js diff --git a/js/qwebircinterface.js b/js/qwebircinterface.js index 4989780..c1eb3c2 100644 --- a/js/qwebircinterface.js +++ b/js/qwebircinterface.js @@ -1,9 +1,11 @@ function qwebirc_ui_onbeforeunload(e) { /* IE sucks */ - var message = "This action will close all active IRC connections."; - var e = e || window.event; - if(e) - e.returnValue = message; - return message; + if(qwebirc.connected) { + var message = "This action will close all active IRC connections."; + var e = e || window.event; + if(e) + e.returnValue = message; + return message; + } } qwebirc.ui.Interface = new Class({ @@ -19,17 +21,55 @@ qwebirc.ui.Interface = new Class({ theme: undefined, baseURL: null, hue: null, + saturation: null, + lightness: null, + thue: null, + tsaturation: null, + tlightness: null, uiOptionsArg: null, + nickValidation: null, + helpURL: null, dynamicBaseURL: "/", - staticBaseURL: "/" + staticBaseURL: "/", + cloak: false }, initialize: function(element, ui, options) { - qwebirc.global = {dynamicBaseURL: options.dynamicBaseURL, staticBaseURL: options.staticBaseURL}; /* HACK */ - this.setOptions(options); + var extractHost = function() { + var uri = document.location.href; + + /* IE6 doesn't have document.origin ... */ + var start = uri.indexOf('?'); + if(start != -1) + uri = uri.substring(0, start); + var start = uri.indexOf('#'); + if(start != -1) + uri = uri.substring(0, start); + + if(QWEBIRC_DEBUG && uri.endsWith(".html")) { + var last = uri.lastIndexOf("/"); + uri = uri.substring(0, last + 1); + } + if(uri.substr(uri.length - 1) != "/") + uri = uri + "/"; + + return uri; + }; + + options.baseURL = extractHost(); + + /* HACK */ + qwebirc.global = { + dynamicBaseURL: options.dynamicBaseURL, + staticBaseURL: options.staticBaseURL, + baseURL: options.baseURL, + helpURL: options.helpURL, + nicknameValidator: $defined(options.nickValidation) ? new qwebirc.irc.NicknameValidator(options.nickValidation) : new qwebirc.irc.DummyNicknameValidator() + }; window.addEvent("domready", function() { var callback = function(options) { + options.cloak = ui_.options.cloak; var IRC = new qwebirc.irc.IRCClient(options, ui_); IRC.connect(); window.onbeforeunload = qwebirc_ui_onbeforeunload; @@ -44,20 +84,26 @@ qwebirc.ui.Interface = new Class({ if(this.options.searchURL) { var args = qwebirc.util.parseURI(String(document.location)); - this.options.hue = this.getHueArg(args); + this.options.hue = this.getHueArg(args, ""); + this.options.saturation = this.getSaturationArg(args, ""); + this.options.lightness = this.getLightnessArg(args, ""); + + this.options.thue = this.getHueArg(args, "t"); + this.options.tsaturation = this.getSaturationArg(args, "t"); + this.options.tlightness = this.getLightnessArg(args, "t"); - if($defined(args["uio"])) - this.options.uiOptionsArg = args["uio"]; + if(args.contains("uio")) + this.options.uiOptionsArg = args.get("uio"); - var url = args["url"]; - var chans, nick = args["nick"]; + var url = args.get("url"); + var chans, nick = args.get("nick"); if($defined(url)) { ichans = this.parseIRCURL(url); if($defined(chans) && chans != "") canAutoConnect = true; } else { - chans = args["channels"]; + chans = args.get("channels"); var canAutoConnect = false; @@ -69,8 +115,9 @@ qwebirc.ui.Interface = new Class({ for(var i=0;i 100 || saturation < -100) + return null; + return saturation; + }, + getLightnessArg: function(args, t) { + var lightness = args.get(t + "lightness"); + if(!$defined(lightness)) + return null; + lightness = parseInt(lightness); + if(lightness > 100 || lightness < -100) + return null; + return lightness; + }, randSub: function(nick) { var getDigit = function() { return Math.floor(Math.random() * 10); } @@ -182,16 +250,14 @@ qwebirc.ui.Interface = new Class({ } if($defined(queryArgs)) { - for(var key_ in queryArgs) { - var value = queryArgs[key_]; - + queryArgs.each(function(key_, value) { if(key_ == "key") { key = value; needkey = true; } else { not_supported.push(key_); } - } + }); } if(needkey) {