]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/qwebircinterface.js
cloak testing
[irc/quakenet/qwebirc.git] / js / qwebircinterface.js
index 046ddc681a65f058659c1bf3a1a9741b5e4d0414..c1eb3c281b579f93f47303bf937387a6ef5bd2cb 100644 (file)
@@ -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({
@@ -21,17 +23,53 @@ qwebirc.ui.Interface = new Class({
     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;
@@ -46,22 +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.saturation = this.getSaturationArg(args);
-        this.options.lightness = this.getLightnessArg(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;
         
@@ -73,8 +115,9 @@ qwebirc.ui.Interface = new Class({
           
             for(var i=0;i<chans.length;i++) {
               chans2[i] = chans[i];
-            
-              if(chans[i].charAt(0) != '#')
+
+                var prefix = chans[i].charAt(0);
+                if(prefix != '#' && prefix != '&')
                 chans2[i] = "#" + chans2[i]
             }
             cdata[0] = chans2.join(",");
@@ -86,12 +129,15 @@ qwebirc.ui.Interface = new Class({
         if($defined(nick))
           inick = this.randSub(nick);
           
-        if(args["randomnick"] && args["randomnick"] == 1)
+        if(args.contains("randomnick") && args.get("randomnick") == 1)
           inick = this.options.initialNickname;
-          
+
+        if(args.contains("cloak") && args.get("cloak") == 1)
+          this.options.cloak = true;
+
         /* we only consider autoconnecting if the nick hasn't been supplied, or it has and it's not "" */
         if(canAutoConnect && (!$defined(inick) || ($defined(inick) && (inick != "")))) {
-          var p = args["prompt"];
+          var p = args.get("prompt");
           var pdefault = false;
           
           if(!$defined(p) || p == "") {
@@ -121,8 +167,8 @@ qwebirc.ui.Interface = new Class({
       var details = ui_.loginBox(callback, inick, ichans, autoConnect, usingAutoNick);
     }.bind(this));
   },
-  getHueArg: function(args) {
-    var hue = args["hue"];
+  getHueArg: function(args, t) {
+    var hue = args.get(t + "hue");
     if(!$defined(hue))
       return null;
     hue = parseInt(hue);
@@ -130,8 +176,8 @@ qwebirc.ui.Interface = new Class({
       return null;
     return hue;
   },
-  getSaturationArg: function(args) {
-    var saturation = args["saturation"];
+  getSaturationArg: function(args, t) {
+    var saturation = args.get(t + "saturation");
     if(!$defined(saturation))
       return null;
     saturation = parseInt(saturation);
@@ -139,8 +185,8 @@ qwebirc.ui.Interface = new Class({
       return null;
     return saturation;
   },
-  getLightnessArg: function(args) {
-    var lightness = args["lightness"];
+  getLightnessArg: function(args, t) {
+    var lightness = args.get(t + "lightness");
     if(!$defined(lightness))
       return null;
     lightness = parseInt(lightness);
@@ -204,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) {