]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Add URL parsing for channels/nick selection.
authorChris Porter <redacted>
Wed, 15 Oct 2008 06:52:58 +0000 (07:52 +0100)
committerChris Porter <redacted>
Wed, 15 Oct 2008 06:52:58 +0000 (07:52 +0100)
Add better login boxes by default.

15 files changed:
compile.bat
compile.sh
js/jslib.js
js/qwebircinterface.js
js/ui/baseui.js
js/ui/genericlogin.js [new file with mode: 0644]
js/ui/mochaui.js
js/ui/qui.js
js/ui/swmui.js
js/ui/uglyui.js
static/css/qui.css
static/mochauidebug.html
static/quidebug.html
static/swmuidebug.html
static/uglyuidebug.html

index 7d1f84888030949368e2c0bb231c2ab220ffa363..f8953de4361b6fd2a44dacb3a62ad98b24ff5df8 100644 (file)
@@ -3,7 +3,7 @@ mkdir compiled
 del /q compiled\*.js\r
 \r
 cd js\r
-copy version.js + jslib.js + irc\ircconnection.js + irc\irclib.js + irc\baseircclient.js + irc\irctracker.js + irc\commandparser.js + irc\ircclient.js + ui\baseui.js + ui\baseuiwindow.js + ui\colour.js + ui\url.js + ui\theme.js + qwebircinterface.js ..\compiled\qwebirc-concat.js /b\r
+copy version.js + jslib.js + irc\ircconnection.js + irc\irclib.js + irc\baseircclient.js + irc\irctracker.js + irc\commandparser.js + irc\ircclient.js + ui\baseui.js + ui\baseuiwindow.js + ui\colour.js + ui\url.js + ui\theme.js + ui\genericlogin.js + qwebircinterface.js ..\compiled\qwebirc-concat.js /b\r
 copy ui\swmlayout.js + ui\swmui.js + irc\commandhistory.js ..\compiled\swmui-concat.js /b\r
 cd ..\compiled\r
 \r
index f6468a64c6714e28baed0433fbb4c1e8a93c2f33..5675fb0a212f92320575ac228f90949afe87f763 100755 (executable)
@@ -3,7 +3,7 @@ mkdir -p compiled
 rm -f compiled/*.js
 
 cd js
-cat version.js jslib.js irc/ircconnection.js irc/irclib.js irc/baseircclient.js irc/irctracker.js irc/commandparser.js irc/ircclient.js ui/baseui.js ui/baseuiwindow.js ui/colour.js ui/url.js ui/theme.js irc/commandhistory.js qwebircinterface.js > ../compiled/qwebirc-concat.js
+cat version.js jslib.js irc/ircconnection.js irc/irclib.js irc/baseircclient.js irc/irctracker.js irc/commandparser.js irc/ircclient.js ui/baseui.js ui/baseuiwindow.js ui/colour.js ui/url.js ui/theme.js ui/genericlogin.js irc/commandhistory.js qwebircinterface.js > ../compiled/qwebirc-concat.js
 cat ui/swmlayout.js ui/swmui.js > ../compiled/swmui-concat.js
 
 error() {
index e5ecbd59abba743066ef07d62c5ea41a1cf10ca0..a1e88c4629bb0e0b12d42c923da5058b7cd4ce26 100644 (file)
@@ -42,3 +42,26 @@ function setAtEnd(obj) {
     obj.setSelectionRange(pos, pos); 
   } 
 }
+
+/* returns the arguments */
+function parseURI(uri) {
+  var result = {}
+
+  var start = uri.indexOf('?');
+  if(start == -1)
+    return result;
+    
+  var querystring = uri.substring(start + 1);
+  
+  var args = querystring.split("&");
+  
+  for(i=0;i<args.length;i++) {
+    var r = args[i].splitMax("=", 2);
+    if(r.length < 2)
+      continue;
+      
+    result[unescape(r[0])] = unescape(r[1]);
+  }
+  
+  return result;
+}
index a08dd6dec5c7aaf5487a64760113f1391d5affc0..8f9562610761e2d157cd77d9c52fafb49bf43ff1 100644 (file)
@@ -3,7 +3,7 @@ var QWebIRCInterface = new Class({
   options: {
     initialNickname: "qwebirc" + Math.ceil(Math.random() * 100000),
     initialChannels: "",
-    searchURL: false,
+    searchURL: true,
     theme: undefined
   },
   initialize: function(element, ui, options) {
@@ -11,18 +11,46 @@ var QWebIRCInterface = new Class({
 
     window.addEvent("domready", function() {
       var ui_ = new ui($(element), new Theme(this.options.theme));
-
-      if(this.options.searchURL) {
-        /* TODO: look at URI and detect nickname/channels... */
-      }
-
-      var details = ui_.loginBox(function(options) {
+      var inick = this.options.initialNickname;
+      var ichans = this.options.initialChannels;
+      var autoNick = true;
+      
+      var callback = function(options) {
         var IRC = new IRCClient(options, ui_);
         IRC.connect();
         window.addEvent("beforeunload", function() {
           IRC.quit("Page closed");
         });
-      }, this.options.initialNickname, this.options.initialChannels);
+      };
+
+      var supplied = false; 
+      if(this.options.searchURL) {
+        var args = parseURI(String(document.location));
+        
+        var chans = args["channels"];
+        var nick = args["nick"];
+
+        if(chans) {
+          chans = chans.split(",");
+          var chans2 = [];
+          
+          for(i=0;i<chans.length;i++) {
+            chans2[i] = chans[i];
+            
+            if(chans[i].charAt(0) != '#')
+              chans2[i] = "#" + chans2[i]
+          }
+          ichans = chans2.join(",");
+          supplied = true;
+        }
+        
+        if(nick) {
+          inick = nick;
+          autoNick = false;
+        }
+      }
+
+      var details = ui_.loginBox(callback, inick, ichans, supplied, autoNick);
     }.bind(this));
   }
 });
index c7b5cac9673906aa9cafcea78aaf6870d8dd957f..bec674b2e357ba9c30da096350afec43607e88dc 100644 (file)
@@ -74,13 +74,36 @@ var BaseUI = new Class({
     
     delete this.windows[window.client][window.identifier];
   },
-  loginBox: function(callback, initialNickname, initialChannels) {
     /*
       this shouldn't be called by overriding classes!
+      they should implement their own!
       some form of user input MUST be received before an
       IRC connection is made, else users are going to get
       tricked into getting themselves glined
     */
+  loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
+    GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
+    /*if(autoConnect) {
+      var c = initialChannels.split(",");
+      var ctext;
+      
+      if(c.length > 1) {
+        var last = c.pop();
+        ctext = c.join(", ") + " and " + last;
+      } else {
+        ctext = c[0];
+      }
+      
+      var nicktext;
+      if(autoNick) {
+        nicktext = "";
+      } else {
+        nicktext = " (as '" + initialNickname + "')"
+      }
+      if(confirm("Connect to IRC and join channels " + ctext + nicktext + "?"))
+        callback({"nickname": initialNickname, "autojoin": initialChannels});
+      return;
+    }
 
     var nick = prompt("Nickname:", initialNickname);
     if(!nick) {
@@ -90,6 +113,7 @@ var BaseUI = new Class({
 
     var chans = prompt("Channels (seperate by comma):", initialChannels);
     callback({"nickname": nick, "autojoin": chans});
+    */
   }
 });
 
diff --git a/js/ui/genericlogin.js b/js/ui/genericlogin.js
new file mode 100644 (file)
index 0000000..5085e40
--- /dev/null
@@ -0,0 +1,119 @@
+function GenericLoginBox(parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick) {
+  if(autoConnect) {
+    ConfirmBox(parentElement, callback, initialNickname, initialChannels, autoNick);
+  } else {
+    LoginBox(parentElement, callback, initialNickname, initialChannels);
+  }
+}
+
+function ConfirmBox(parentElement, callback, initialNickname, initialChannels, autoNick) {
+  var box = new Element("div");
+  box.addStyle("confirmbox");
+  parentElement.appendChild(box);
+
+  var nick = new Element("b");
+  nick.set("text", initialNickname);
+  
+  var c = initialChannels.split(",");
+  var ctext;
+  
+  if(c.length > 1) { 
+    var last = c.pop();
+    ctext = c.join(", ") + " and " + last;
+  } else {
+    ctext = c.join(", ");
+  }
+  
+  var channels = new Element("b");
+  channels.set("text", ctext);
+  
+  var text = new Element("div");
+  text.appendChild(document.createTextNode("To connect to IRC and join channels "));
+  text.appendChild(channels);
+  
+  if(!autoNick) {
+    text.appendChild(document.createTextNode(" as "));
+    text.appendChild(nick);
+  }    
+  text.appendChild(document.createTextNode(" click 'Connect'."));
+
+  box.appendChild(text);
+  
+  var form = new Element("form");
+  box.appendChild(form);
+  
+  var yes = new Element("input", {"type": "submit", "value": "Connect"});
+  form.appendChild(yes);
+  
+  form.addEvent("submit", function(e) {
+    new Event(e).stop();
+    parentElement.removeChild(box);
+    callback({"nickname": initialNickname, "autojoin": initialChannels});
+  });
+}
+
+function LoginBox(parentElement, callback, initialNickname, initialChannels) {
+  var box = new Element("div");
+  parentElement.appendChild(box);
+  box.addStyle("loginbox");
+  
+  var header = new Element("h1");
+  header.set("text", "Connect to IRC");
+  box.appendChild(header);
+
+  var form = new Element("form");
+  box.appendChild(form);
+
+  var boxtable = new Element("table");
+  form.appendChild(boxtable);
+
+  var tbody = new Element("tbody");
+  boxtable.appendChild(tbody); /* stupid IE */
+
+  function createRow(label, e2) {
+    var r = new Element("tr");
+    tbody.appendChild(r);
+
+    var d1 = new Element("td");
+    if(label)
+      d1.set("text", label);
+    r.appendChild(d1);
+
+    var d2 = new Element("td");
+    r.appendChild(d2);
+    d2.appendChild(e2);
+    return d1;
+  }
+
+  var nick = new Element("input");
+  createRow("Nickname:", nick);
+  var chan = new Element("input");
+  createRow("Channels (comma seperated):", chan);
+
+  var connbutton = new Element("input", {"type": "submit"});
+  connbutton.set("value", "Connect");
+  createRow(undefined, connbutton)
+
+  form.addEvent("submit", function(e) {
+    new Event(e).stop();
+    var nickname = nick.value;
+    var chans = chan.value;
+    if(chans == "#") /* sorry channel "#" :P */
+      chans = "";
+
+    if(!nickname) {
+      alert("You must supply a nickname.");
+      nick.focus();
+      return;
+    }
+
+    parentElement.removeChild(box);
+    
+    callback({"nickname": nickname, "autojoin": chans});
+  }.bind(this));
+
+  nick.set("value", initialNickname);
+  chan.set("value", initialChannels);
+
+  nick.focus();
+}
\ No newline at end of file
index 655240de80fa6dcb3ab5f28eedc8e81b31c03a6d..bd0299f6b7ea4e97f4b6a68bc5ed3b98d0643936 100644 (file)
@@ -217,10 +217,10 @@ var QMochaUI = new Class({
     form.appendChild(inputbox);
     inputbox.focus();
   },
-  loginBox: function(callbackfn, intialNickname, initialChannels) {
+  loginBox: function(callbackfn, intialNickname, initialChannels, autoConnect, autoNick) {
     this.parent(function(options) {
       this.postInitialize();
       callbackfn(options);
-    }.bind(this), intialNickname, initialChannels);
+    }.bind(this), intialNickname, initialChannels, autoConnect);
   }
 });
index c0cadfc2647076e221b217b4fb5d6c05cfb9a6c4..7ad907f8ff9a0dfb483dfe019c85a9bfd0adc56d 100644 (file)
@@ -4,11 +4,12 @@ var QUIWindow = new Class({
   initialize: function(parentObject, client, type, name) {
     this.parent(parentObject, client, type, name);
 
-    this.tab = new Element("span");
+    this.tab = new Element("a", {"href": "#"});
     this.tab.addClass("tab");
     
     this.tab.appendText(name);
-    this.tab.addEvent("click", function() {
+    this.tab.addEvent("click", function(e) {
+      new Event(e).stop();
       parentObject.selectWindow(this);
     }.bind(this));
 
@@ -79,20 +80,21 @@ var QUIWindow = new Class({
     var bottompos = formdiv.getSize().y;
     
     if(type == WINDOW_CHANNEL) {
-      this.nicklist = new Element("div");
-      this.nicklist.addClass("nicklist");
-      this.nicklist.setStyle("bottom", (bottompos - 1) + "px");
-      
-      this.window.appendChild(this.nicklist);
-      rightpos = this.nicklist.getSize().x;
-
       this.topic = new Element("div");
       this.topic.addClass("topic");
       this.topic.set("html", "&nbsp;");
-      this.topic.setStyle("right", rightpos + "px");
+      this.topic.setStyle("right", "0px");
       this.window.appendChild(this.topic);
       
       toppos = this.topic.getSize().y;
+
+      this.nicklist = new Element("div");
+      this.nicklist.addClass("nicklist");
+      this.nicklist.setStyle("top", toppos + "px");
+      this.nicklist.setStyle("bottom", (bottompos - 1) + "px");
+      
+      this.window.appendChild(this.nicklist);
+      rightpos = this.nicklist.getSize().x;
     }
 
     this.lines.setStyle("top", toppos + "px");
@@ -130,7 +132,13 @@ var QUIWindow = new Class({
     while(t.firstChild)
       t.removeChild(t.firstChild);
 
-    Colourise(topic, t);
+    if(topic) {
+      Colourise(topic, "[" + topic + "]");
+    } else {
+      var e = new Element("(no topic set)");
+      e.addClass("emptytopic");
+      topic.appendChild(e);
+    }
   },
   select: function() {
     this.window.removeClass("tab-invisible");
@@ -208,10 +216,10 @@ var QUI = new Class({
     this.container.addClass("container");
     this.outerContainer.appendChild(this.container);
   },
-  loginBox: function(callbackfn, intialNickname, initialChannels) {
+  loginBox: function(callbackfn, intialNickname, initialChannels, autoConnect, autoNick) {
     this.parent(function(options) {
       this.postInitialize();
       callbackfn(options);
-    }.bind(this), intialNickname, initialChannels);
+    }.bind(this), intialNickname, initialChannels, autoConnect, autoNick);
   }
 });
index 6fc8cb135e3a370b3e23e4aa62ff5fa10d1d79db..c353cca672efbf52b1444566a24319581c118f53 100644 (file)
@@ -161,68 +161,10 @@ var SWMUI = new Class({
   resize: function() {
     window.fireEvent("resize");
   },
-  loginBox: function(callback, initialNickname, initialChannels) {
-    var box = new Element("div");
-    this.parentElement.appendChild(box);
-
-    var header = new Element("h1");
-    header.set("text", "qwebirc");
-    box.appendChild(header);
-
-    var form = new Element("form");
-    box.appendChild(form);
-
-    var boxtable = new Element("table");
-    form.appendChild(boxtable);
-
-    var tbody = new Element("tbody");
-    boxtable.appendChild(tbody); /* stupid IE */
-
-    function createRow(label, e2) {
-      var r = new Element("tr");
-      tbody.appendChild(r);
-
-      var d1 = new Element("td");
-      if(label)
-        d1.set("text", label);
-      r.appendChild(d1);
-
-      var d2 = new Element("td");
-      r.appendChild(d2);
-      d2.appendChild(e2);
-      return d1;
-    }
-
-    var nick = new Element("input");
-    createRow("Nickname:", nick);
-    var chan = new Element("input");
-    createRow("Channels (comma seperated):", chan);
-
-    var connbutton = new Element("input", {"type": "submit"});
-    connbutton.set("value", "Connect");
-    createRow(undefined, connbutton)
-
-    form.addEvent("submit", function(e) {
-      new Event(e).stop();
-      var nickname = nick.value;
-      var chans = chan.value;
-      if(chans == "#") /* sorry channel "#" :P */
-        chans = "";
-
-      if(!nickname) {
-        alert("You must supply a nickname.");
-        nick.focus();
-        return;
-      }
-
-      this.parentElement.removeChild(box);
+  loginBox: function(callback, initialNickname, initialChannels, autoConnect) {
+    this.parent(function(options) {
       this.postInitialize();
-      callback({"nickname": nickname, "autojoin": chans});
-    }.bind(this));
-
-    nick.set("value", initialNickname);
-    chan.set("value", initialChannels);
-
-    nick.focus();
+      callbackfn(options);
+    }.bind(this), intialNickname, initialChannels, autoConnect);
   }
 });
index d07ea88f15acd3293225d9155516a7aadabd904d..de3e6a34971bf8983ebc4e666435cc0e5754590b 100644 (file)
@@ -156,11 +156,11 @@ var UglyUI = new Class({
     form.appendChild(inputbox);
     inputbox.focus();
   },
-  loginBox: function(callbackfn, intialNickname, initialChannels) {
+  loginBox: function(callbackfn, intialNickname, initialChannels, autoConnect, autoNick) {
     this.parent(function(options) {
       this.postInitialize();
       callbackfn(options);
-    }.bind(this), intialNickname, initialChannels);
+    }.bind(this), intialNickname, initialChannels, autoConnect, autoNick);
   }
 });
 
index 71d52207543b801867c8b3060339d5393d7c3272..b5204d1ae8eb012cb003659722299a902e2fe5a8 100644 (file)
@@ -1,21 +1,46 @@
 .qwebirc-qui .tabbar {
-  border: 1px solid black;
+  border: 1px solid #c3cee0;
   padding: 4px;
+  background: #e2ecf9;
   font-size: 0.8em;
   font-family: Verdana, sans-serif;
+  color: #000000;
 }
 
 .qwebirc-qui .tab {
-  border: 1px black solid;
+  border: 1px solid #e2ecf9;
   padding: 2px;
   cursor: default;
   margin-right: 2px;
-  background: #eee;
   clear: both;
 }
 
+.qwebirc-qui a.tab {
+  text-decoration: none;
+  color: #000000;
+}
+
+.qwebirc-qui a.tab:visited {
+  color: #000000;
+}
+
+.qwebirc-qui .tab:hover {
+  background: #ffffff;
+  border: 1px solid #c8d2dc;
+  -moz-border-radius: 4px;
+  -webkit-border-radius: 4px;
+}
+
+.qwebirc-qui .tab-selected {
+  background: #ffffff;
+  border: 1px solid #c8d2dc;
+  -moz-border-radius: 4px;
+  -webkit-border-radius: 4px;
+  color: #333333;
+}
+
 .qwebirc-qui .input input {
-  border: 0px solid black;
+  border: 0px;
   margin: 2px 0px 0px 0px;
   width: 100%;
   font-family: Verdana, sans-serif;
   right: 0px;
   bottom: 0px;
   position: absolute;
-  border-top: 1px solid black;
+  border-top: 1px solid #c8d2dc;
+  padding-left: 2px;
+  padding-right: 2px;
 }
 
 .qwebirc-qui .tabclose {
-  border: 1px black solid;
   margin-left: 5px;
   padding: 2px;
-  font-size: 0.5em;
+  font-size: 0.7em;
+  vertical-align: top;
+  -moz-border-radius: 2px;
+  -webkit-border-radius: 2px;
 }
 
 .qwebirc-qui .nicklist {
-  border-left: 1px solid black;
+  border-left: 1px solid #c8d2dc;
   position: absolute;
   top: 0px;
   right: 0px;
   width: 125px;
   overflow: auto;
-  background: white;
+  background: #f2f0ff;
+  color: black;
   font-family: Verdana, sans-serif;
   font-size: 0.7em;
 }
   display: none;
 }
 
-.qwebirc-qui .tab-selected {
-  background: #eeffff;
-}
-
-.qwebirc-qui .linestyle1 {
+/*.qwebirc-qui .linestyle1 {
   background: #efefef;
 }
 
 .qwebirc-qui .linestyle2 {
   background: #eeffff;
-}
+}*/
 
 .qwebirc-qui .tab-hilighted {
   color: red;
   position: absolute;
   left: 0px;
   top: 0px;
+  background-color: #F2F0FF;
+  border-bottom: 1px dashed #c8d2dc;
+}
+
+.qwebirc-qui .topic .emptytopic {
+  color: grey;
 }
 
 .qwebirc-qui .lines {
   overflow: auto;
   position: absolute;
   left: 0px;
-  font-family: Consolas, "Lucida Console", monospace, sans-serif;
+  font-family: Verdana;
+  font-size: 0.8em;
+  background: #f2f0ff;
 }
 
 .qwebirc-qui .lines div {
index 6061551d5f51a6c2e3953ceebc58debfdd29c0bf..c52d91816030174df52b1b3431cc182ad1b86074 100644 (file)
@@ -26,6 +26,7 @@
   <script type="text/javascript" src="js/debug/ui/colour.js"></script>
   <script type="text/javascript" src="js/debug/ui/url.js"></script>
   <script type="text/javascript" src="js/debug/ui/theme.js"></script>
+  <script type="text/javascript" src="js/debug/ui/genericlogin.js"></script>
   <script type="text/javascript" src="js/debug/ui/mochaui.js"></script>
   <script type="text/javascript" src="js/debug/qwebircinterface.js"></script>
   <script type="text/javascript">
index cf37a284d8db9a1a27ea19bf88ddc7bf2b555f6d..5a957341b7edda3812bb474725f3a74d0c7c6daa 100644 (file)
@@ -19,6 +19,7 @@
   <script type="text/javascript" src="js/debug/ui/colour.js"></script>
   <script type="text/javascript" src="js/debug/ui/url.js"></script>
   <script type="text/javascript" src="js/debug/ui/theme.js"></script>
+  <script type="text/javascript" src="js/debug/ui/genericlogin.js"></script>
   <script type="text/javascript" src="js/debug/ui/qui.js"></script>
   <script type="text/javascript" src="js/debug/qwebircinterface.js"></script>
   <script type="text/javascript">
index bad518c98be347041121dc02276cb0de968c7b8c..1880182be1536b36741d1fda733cfd65aef1c581 100644 (file)
@@ -19,6 +19,7 @@
   <script type="text/javascript" src="js/debug/ui/colour.js"></script>
   <script type="text/javascript" src="js/debug/ui/url.js"></script>
   <script type="text/javascript" src="js/debug/ui/theme.js"></script>
+  <script type="text/javascript" src="js/debug/ui/genericlogin.js"></script>
   <script type="text/javascript" src="js/debug/ui/swmlayout.js"></script>
   <script type="text/javascript" src="js/debug/ui/swmui.js"></script>
   <script type="text/javascript" src="js/debug/qwebircinterface.js"></script>
index eb4a49ade361f330e75d06ddd5fcfd78329b6dce..ce8dc22440aa1df402175b0e235c47a6c57aa823 100644 (file)
@@ -19,6 +19,7 @@
   <script type="text/javascript" src="js/debug/ui/colour.js"></script>
   <script type="text/javascript" src="js/debug/ui/url.js"></script>
   <script type="text/javascript" src="js/debug/ui/theme.js"></script>
+  <script type="text/javascript" src="js/debug/ui/genericlogin.js"></script>
   <script type="text/javascript" src="js/debug/ui/uglyui.js"></script>
   <script type="text/javascript" src="js/debug/qwebircinterface.js"></script>
   <script type="text/javascript">