X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/d65fe45f15fdd9ee754fb3d0adcea75956bccb6a..402966243a3e711ce1ab6b29dbac38a88d7a0850:/js/qwebircinterface.js diff --git a/js/qwebircinterface.js b/js/qwebircinterface.js index a08dd6d..5d5035b 100644 --- a/js/qwebircinterface.js +++ b/js/qwebircinterface.js @@ -1,28 +1,237 @@ -var QWebIRCInterface = new Class({ +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; +} + +qwebirc.ui.Interface = new Class({ Implements: [Options], options: { initialNickname: "qwebirc" + Math.ceil(Math.random() * 100000), initialChannels: "", - searchURL: false, - theme: undefined + networkName: "ExampleNetwork", + networkServices: [], + loginRegex: null, + appTitle: "ExampleNetwork Web IRC", + searchURL: true, + theme: undefined, + baseURL: null, + hue: null, + saturation: null, + lightness: null, + uiOptionsArg: null, + nickValidation: null, + dynamicBaseURL: "/", + staticBaseURL: "/" }, initialize: function(element, ui, options) { this.setOptions(options); + + /* HACK */ + qwebirc.global = { + dynamicBaseURL: options.dynamicBaseURL, + staticBaseURL: options.staticBaseURL, + nicknameValidator: $defined(options.nickValidation) ? new qwebirc.irc.NicknameValidator(options.nickValidation) : new qwebirc.irc.DummyNicknameValidator() + }; window.addEvent("domready", function() { - var ui_ = new ui($(element), new Theme(this.options.theme)); + var callback = function(options) { + var IRC = new qwebirc.irc.IRCClient(options, ui_); + IRC.connect(); + window.onbeforeunload = qwebirc_ui_onbeforeunload; + window.addEvent("unload", function() { + IRC.quit("Page closed"); + }); + }; + var inick = null; + var ichans = this.options.initialChannels; + var autoConnect = false; + if(this.options.searchURL) { - /* TODO: look at URI and detect nickname/channels... */ + var args = qwebirc.util.parseURI(String(document.location)); + this.options.hue = this.getHueArg(args); + this.options.saturation = this.getSaturationArg(args); + this.options.lightness = this.getLightnessArg(args); + + if($defined(args["uio"])) + this.options.uiOptionsArg = args["uio"]; + + var url = args["url"]; + var chans, nick = args["nick"]; + + if($defined(url)) { + ichans = this.parseIRCURL(url); + if($defined(chans) && chans != "") + canAutoConnect = true; + } else { + chans = args["channels"]; + + var canAutoConnect = false; + + if(chans) { + var cdata = chans.split(" "); + + chans = cdata[0].split(","); + var chans2 = []; + + for(var i=0;i 360 || hue < 0) + return null; + return hue; + }, + getSaturationArg: function(args) { + var saturation = args["saturation"]; + if(!$defined(saturation)) + return null; + saturation = parseInt(saturation); + if(saturation > 100 || saturation < -100) + return null; + return saturation; + }, + getLightnessArg: function(args) { + var lightness = args["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); } + + return nick.split("").map(function(v) { + if(v == ".") { + return getDigit(); + } else { + return v; + } + }).join(""); + + }, + parseIRCURL: function(url) { + if(url.indexOf(":") == 0) + return; + var schemeComponents = url.splitMax(":", 2); + if(schemeComponents[0].toLowerCase() != "irc" && schemeComponents[0].toLowerCase() != "ircs") { + alert("Bad IRC URL scheme."); + return; + } + + if(url.indexOf("/") == 0) { + /* irc: */ + return; + } + + var pathComponents = url.splitMax("/", 4); + if(pathComponents.length < 4 || pathComponents[3] == "") { + /* irc://abc */ + return; + } + + var args, queryArgs; + if(pathComponents[3].indexOf("?") > -1) { + queryArgs = qwebirc.util.parseURI(pathComponents[3]); + args = pathComponents[3].splitMax("?", 2)[0]; + } else { + args = pathComponents[3]; + } + var parts = args.split(","); + + var channel = parts[0]; + if(channel.charAt(0) != "#") + channel = "#" + channel; + + var not_supported = [], needkey = false, key; + for(var i=1;i 0) + alert("The following IRC URL components were not accepted: " + not_supported.join(", ") + "."); + + return channel; } });