]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/panes/options.js
Add dynamic setting of UI options in URL.
[irc/quakenet/qwebirc.git] / js / ui / panes / options.js
index 21e8f7a8dcfcb20e7fa0954d77932f7bd7243ac9..2422f75e221d6b4960852e1ab97a9216bc1b33fc 100644 (file)
@@ -9,6 +9,10 @@ qwebirc.ui.supportsFocus = function() {
   return [true];
 }
 
+/**
+ * Note that options are settable by the uioptions url arg by default unless you specifiy
+ * settableByURL...
+ */
 qwebirc.config.DEFAULT_OPTIONS = [
   [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity (requires Flash)", true, {
     enabled: function() {
@@ -26,9 +30,13 @@ qwebirc.config.DEFAULT_OPTIONS = [
   }],
   [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
   [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
-  [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in nicklist", true],
-  [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true],
-  [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true],
+  [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in channel lines", true],
+  [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true, {
+    settableByURL: false
+  }],
+  [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true, {
+    settableByURL: false
+  }],
   [8, "LASTPOS_LINE", "Show a last position indicator for each window", true, {
     enabled: qwebirc.ui.supportsFocus
   }],
@@ -115,11 +123,15 @@ qwebirc.config.HueInput = new Class({
     var i = new Element("div");
     i.addClass("qwebirc-optionspane");
     i.addClass("hue-slider");
-    
     this.parentElement.appendChild(i);
     
     var k = new Element("div");
     k.addClass("knob");
+    if(Browser.Engine.trident) {
+      k.setStyle("top", "0px");
+      k.setStyle("background-color", "black");
+    }
+    
     i.appendChild(k);
     
     var slider = new Slider(i, k, {steps: 36, range: [0, 369], wheel: true});
@@ -209,12 +221,18 @@ qwebirc.config.Option = new Class({
         this.default_ = enabledResult[1];
     } else {
       this.enabled = true;
-    }    
+    }
+    
+    if($defined(extras) && $defined(extras.settableByURL)) {
+      this.settableByURL = extras.settableByURL;
+    } else {
+      this.settableByURL = true;
+    }
   },
   setSavedValue: function(x) {
     if(this.enabled)
       this.value = x;
-  },
+  }
 });
 
 qwebirc.config.RadioOption = new Class({
@@ -291,10 +309,12 @@ qwebirc.ui.Options = new Class({
         var type;
         if(stype == "boolean") {
           type = qwebirc.config.CheckOption;
-        } else {
+        } else if(stype == "function") {
           var options = default_();
           type = options.class_;
-          defualt_ = options.default_;
+          default_ = options.default_;
+        } else {
+          type = qwebirc.config.TextOption;
         }
         return new type(optionId, prefix, label, default_, moreextras);
       }
@@ -405,6 +425,41 @@ qwebirc.ui.CookieOptions = new Class({
   }
 });
 
+qwebirc.ui.SuppliedArgOptions = new Class({
+  Extends: qwebirc.ui.CookieOptions,
+  initialize: function(ui, arg) {
+    var p = {};
+    
+    if($defined(arg) && arg != "") {
+      var decoded = qwebirc.util.b64Decode(arg);
+      if(decoded)
+        p = qwebirc.util.parseURI("?" + decoded);
+    }
+    
+    this.parsedOptions = p;
+    this.parent(ui);
+  },
+  _get: function(x) {
+    if(x.settableByURL !== true)
+      return this.parent(x);
+
+    var opt = this.parsedOptions[x.optionId];
+    if(!$defined(opt))
+      return this.parent(x);
+      
+    return opt;
+  },
+  serialise: function() {
+    var result = [];
+    this.getOptionList().forEach(function(x) {
+      if(x.settableByURL && x.default_ != x.value)
+        result.push(x.optionId + "=" + x.value);
+    }.bind(this));
+    
+    return qwebirc.util.b64Encode(result.join("&")).replaceAll("=", "");
+  }
+});
+
 qwebirc.ui.DefaultOptionsClass = new Class({
-  Extends: qwebirc.ui.CookieOptions
+  Extends: qwebirc.ui.SuppliedArgOptions
 });