]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/swmui.js
Try not to corrupt the namespaces.
[irc/quakenet/qwebirc.git] / js / ui / swmui.js
index 9ffdda92e9c113b37a9b7d074274043288b0096a..50957e303245ae089760d1d47c110b0195a8009e 100644 (file)
@@ -1,22 +1,77 @@
-var SWMUIWindow = new Class({
-  Extends: UIWindow,
+qwebirc.ui.SWMUI = new Class({
+  Extends: qwebirc.ui.NewLoginUI,
+  initialize: function(parentElement, theme) {
+    this.parent(parentElement, qwebirc.ui.SWMUI.Window, "swmui");
+
+    this.parentElement = parentElement;
+    this.theme = theme;
+  },
+  postInitialize: function() {
+    this.rootFrame = new qwebirc.ui.SWMUI.Frame(this.parentElement);
+
+    this.tabPanel = new qwebirc.ui.SWMUI.Panel(this.rootFrame);
+    this.tabPanel.anchor = qwebirc.ui.SWMUI.SWM_ANCHOR_TOP;
+    this.tabPanel.addClass("tabs");
+    
+    this.mainPanel = new qwebirc.ui.SWMUI.Panel(this.rootFrame);
+    this.mainPanel.addClass("main");
+    
+    this.entryPanel = new qwebirc.ui.SWMUI.Panel(this.rootFrame);
+    this.entryPanel.anchor = qwebirc.ui.SWMUI.SWM_ANCHOR_BOTTOM;
+    this.entryPanel.addClass("entry");
+
+    var form = new Element("form");
+    
+    var inputbox = new Element("input");
+    inputbox.setStyle("border", "0px");
+    
+    window.addEvent("resize", function() {
+      var s = this.entryPanel.getInnerSize().x;
+      inputbox.setStyle("width", s + "px");
+    }.bind(this));
+
+    form.addEvent("submit", function(e) {
+      new Event(e).stop();
+    
+      this.getActiveWindow().client.exec(inputbox.value);
+      inputbox.value = "";
+    }.bind(this));
+
+    this.entryPanel.appendChild(form);
+    form.appendChild(inputbox);
+    inputbox.focus();
+
+    this.resize();
+  },
+  showInput: function(state) {
+    this.entryPanel.setHidden(state);
+    this.resize();
+  },
+  resize: function() {
+    window.fireEvent("resize");
+  }
+});
+
+qwebirc.ui.SWMUI.Window = new Class({
+  Extends: qwebirc.ui.Window,
   
   initialize: function(parentObject, client, type, name) {
     this.parent(parentObject, client, type, name);
-    this.contentPanel = new SWMPanel(parentObject.mainPanel, true);
+    this.contentPanel = new qwebirc.ui.SWMUI.Panel(parentObject.mainPanel, true);
     this.contentPanel.addClass("content");
 
-    if(type == WINDOW_CHANNEL) {
-      this.nickList = new SWMPanel(this.contentPanel);
-      this.nickList.anchor = SWM_ANCHOR_RIGHT;
+    if(type == qwebirc.ui.WINDOW_CHANNEL) {
+      this.nickList = new qwebirc.ui.SWMUI.Panel(this.contentPanel);
+      this.nickList.anchor = qwebirc.ui.SWMUI.SWM_ANCHOR_RIGHT;
       this.nickList.addClass("nicklist");
 
-      this.topic = new SWMPanel(this.contentPanel);
-      this.topic.anchor = SWM_ANCHOR_TOP;
+      this.topic = new qwebirc.ui.SWMUI.Panel(this.contentPanel);
+      this.topic.anchor = qwebirc.ui.SWMUI.SWM_ANCHOR_TOP;
       this.topic.addClass("topic");
     }
     
-    this.lines = new SWMPanel(this.contentPanel);
+    this.xlines = new qwebirc.ui.SWMUI.Panel(this.contentPanel);
+    this.lines = this.xlines.element;
     
     this.tab = new Element("span");
     this.tab.addClass("tab");
@@ -29,13 +84,13 @@ var SWMUIWindow = new Class({
     parentObject.tabPanel.appendChild(this.tab);
     parentObject.resize();
     
-    if(type != WINDOW_STATUS) {
+    if(type != qwebirc.ui.WINDOW_STATUS && type != qwebirc.ui.WINDOW_CONNECT) {
       tabclose = new Element("span");
       tabclose.addClass("tabclose");
       tabclose.addEvent("click", function(e) {
         new Event(e).stop();
         
-        if(type == WINDOW_CHANNEL)
+        if(type == qwebirc.ui.WINDOW_CHANNEL)
           this.client.exec("/PART " + name);
 
         this.close();
@@ -69,9 +124,9 @@ var SWMUIWindow = new Class({
 
     this.contentPanel.setHidden(false);
     this.parentObject.resize();
-    this.tab.removeClass("tab-highlighted");
     this.tab.removeClass("tab-unselected");
     this.tab.addClass("tab-selected");
+    this.parentObject.showInput(this.type == qwebirc.ui.WINDOW_CONNECT || this.type == qwebirc.ui.WINDOW_CUSTOM);
   },
   deselect: function() {
     this.parent();
@@ -88,8 +143,6 @@ var SWMUIWindow = new Class({
     this.parentObject.tabPanel.removeChild(this.tab);
   },
   addLine: function(type, line, colour) {
-    this.parent(type, line, colour);
-    
     var e = new Element("div");
 
     if(colour) {
@@ -100,136 +153,17 @@ var SWMUIWindow = new Class({
       e.addClass("linestyle2");
     }
     
-    if(type)
-      line = this.parentObject.theme.message(type, line);
-    
-    Colourise(IRCTimestamp(new Date()) + " " + line, e);
-    
     this.lastcolour = !this.lastcolour;
 
-    var prev = this.lines.element.getScroll();
-    var prevbottom = this.lines.element.getScrollSize().y;
-    var prevsize = this.lines.element.getSize();
-    this.lines.appendChild(e);
-  
-    if(prev.y + prevsize.y == prevbottom)
-      this.lines.element.scrollTo(prev.x, this.lines.element.getScrollSize().y);
-    
-    if(!this.active)
-      this.tab.addClass("tab-highlighted");
-  }
-});
-
-var SWMUI = new Class({
-  Extends: UI,
-  initialize: function(parentElement, theme) {
-    this.parent(parentElement, SWMUIWindow, "swmui");
-
-    this.parentElement = parentElement;
-    this.theme = theme;
+    this.parent(type, line, colour, e);
   },
-  postInitialize: function() {
-    this.rootFrame = new SWMFrame(this.parentElement);
-
-    this.tabPanel = new SWMPanel(this.rootFrame);
-    this.tabPanel.anchor = SWM_ANCHOR_TOP;
-    this.tabPanel.addClass("tabs");
-    
-    this.mainPanel = new SWMPanel(this.rootFrame);
-    this.mainPanel.addClass("main");
-    
-    this.entryPanel = new SWMPanel(this.rootFrame);
-    this.entryPanel.anchor = SWM_ANCHOR_BOTTOM;
-    this.entryPanel.addClass("entry");
-
-    var form = new Element("form");
-    
-    var inputbox = new Element("input");
-    inputbox.setStyle("border", "0px");
+  setHilighted: function(state) {
+    this.parent(state);
     
-    window.addEvent("resize", function() {
-      var s = this.entryPanel.getInnerSize().x;
-      inputbox.setStyle("width", s + "px");
-    }.bind(this));
-
-    form.addEvent("submit", function(e) {
-      new Event(e).stop();
-    
-      this.getActiveWindow().client.exec(inputbox.value);
-      inputbox.value = "";
-    }.bind(this));
-
-    this.entryPanel.appendChild(form);
-    form.appendChild(inputbox);
-    inputbox.focus();
-
-    this.resize();
-  },
-  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;
+    if(state) {
+      this.tab.addClass("tab-highlighted");
+    } else {
+      this.tab.removeClass("tab-highlighted");
     }
-
-    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);
-      this.postInitialize();
-      callback({"nickname": nickname, "autojoin": chans});
-    }.bind(this));
-
-    nick.set("value", initialNickname);
-    chan.set("value", initialChannels);
-
-    nick.focus();
   }
 });