]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/mochaui.js
Close last active request on disconnect and erase timers.
[irc/quakenet/qwebirc.git] / js / ui / mochaui.js
index e88be6123a227fbcb1ba1095885a2fd061b18484..8eb1b583b503e7e6fd9be3b956f7f9814bc039d6 100644 (file)
@@ -1,40 +1,98 @@
-var QMochaUIWindow = new Class({
-  Extends: UIWindow,
-  
-  initialize: function(parentObject, client, type, name) {
-    this.parent(parentObject, client, type, name);
-
-    this.lines = new Element("div", {styles: {overflow: "auto", "width": "90"}});
-
-    this.form = new Element("form");
-    this.inputbox = new Element("input", {styles: {border: 0, width: "100%"}});
-    this.inputbox.addClass("input");
-    this.scrolltimeout = null;
+qwebirc.ui.MochaUI = new Class({
+  Extends: qwebirc.ui.NewLoginUI,
+  initialize: function(parentElement, theme) {
+    this.parent(parentElement, qwebirc.ui.MochaUI.Window, "mochaui");
+    this.theme = theme;
+    this.parentElement = parentElement;
     
-    this.inputbox.addEvent("focus", function() {
-      /* TODO: bring to top */
-      //alert(":O");
-      //alert(this.windowObject.windowEl);
-      //MochaUI.focusWindow.pass(this.windowObject.windowEl, this.windowObject);
-      //this.windowObject.focusWindow();
-      this.parentObject.selectWindow(this);
+    window.addEvent("domready", function() {
+      /* determine input size */
+      var l = new Element("input", {styles: {border: 0}});
+      this.parentElement.appendChild(l);
+      this.inputHeight = l.getSize().y;
+      this.parentElement.removeChild(l);
+      
+      MochaUI.Desktop = new MochaUI.Desktop();
+      MochaUI.Dock = new MochaUI.Dock({
+        dockPosition: "top"
+      });
+
+      MochaUI.Modal = new MochaUI.Modal();
+      MochaUI.options.useEffects = false;
     }.bind(this));
     
-    this.form.addEvent("submit", function(e) {
+    window.addEvent("unload", function() {
+      if(MochaUI)
+        MochaUI.garbageCleanUp();
+    });
+  },
+  postInitialize: function() {    
+    return;
+    this.tabs = new Element("div");
+    this.tabs.addClass("tabbar");
+    
+    this.parentElement.appendChild(this.tabs);
+    
+    this.container = new Element("div");
+    this.container.addClass("container");
+    
+    this.parentElement.appendChild(this.container);
+  
+    var form = new Element("form");
+    var inputbox = new Element("input");
+    inputbox.addClass("input");
+  
+    form.addEvent("submit", function(e) {
       new Event(e).stop();
     
-      this.client.exec(this.inputbox.value);
-      this.inputbox.value = "";
+      this.getActiveWindow().client.exec(inputbox.value);
+      inputbox.value = "";
     }.bind(this));
-    //this.container.appendChild(form);  
-    this.form.appendChild(this.inputbox);
+    this.parentElement.appendChild(form);  
+    form.appendChild(inputbox);
+    inputbox.focus();
+  }
+});
+
+qwebirc.ui.MochaUI.Window = new Class({
+  Extends: qwebirc.ui.Window,
+  
+  initialize: function(parentObject, client, type, name) {
+    this.parent(parentObject, client, type, name);
+
+    this.lines = new Element("div", {styles: {overflow: "auto", "width": "90"}});
+
+    var toolbar = (type != qwebirc.ui.WINDOW_CUSTOM) && (type != qwebirc.ui.WINDOW_CONNECT);
+    
+    if(toolbar) {
+      this.form = new Element("form");
+      this.inputbox = new Element("input", {styles: {border: 0, width: "100%"}});
+      this.inputbox.addClass("input");
+    
+      this.inputbox.addEvent("focus", function() {
+        /* TODO: bring to top */
+        //alert(":O");
+        //alert(this.windowObject.windowEl);
+        //MochaUI.focusWindow.pass(this.windowObject.windowEl, this.windowObject);
+        //this.windowObject.focusWindow();
+        this.parentObject.selectWindow(this);
+      }.bind(this));
+    
+      this.form.addEvent("submit", function(e) {
+        new Event(e).stop();
+      
+        this.client.exec(this.inputbox.value);
+        this.inputbox.value = "";
+      }.bind(this));
+      //this.container.appendChild(form);  
+      this.form.appendChild(this.inputbox);
+    }
     
     var prefs = {
       width: 800,
       height: 400,
       title: name,
       footerHeight: 0,
-      toolbar: true,
       container: $("pageWrapper"),
       toolbarHeight: parentObject.inputHeight,
       toolbarPosition: "bottom",
@@ -48,18 +106,14 @@ var QMochaUIWindow = new Class({
         parentObject.selectWindow(this);
       }.bind(this),
       onClose: function() {
-        if(type == WINDOW_CHANNEL)
+        if(type == qwebirc.ui.WINDOW_CHANNEL)
           this.client.exec("/PART " + name);
-        if($defined(this.scrolltimeout)) {
-          $clear(this.scrolltimeout);
-          this.scrolltimeout = null;
-        }
         this.close();
       }.bind(this)
     };
     
-    if(type == WINDOW_STATUS)
-      prefs.closable = false;
+    prefs.toolbar = toolbar;
+    prefs.closable = type != qwebirc.ui.WINDOW_STATUS && type != qwebirc.ui.WINDOW_CONNECT;
     
     /* HACK */
 /*    var oldIndexLevel = MochaUI.Windows.indexLevel;
@@ -72,6 +126,7 @@ var QMochaUIWindow = new Class({
     }
   */  
     var nw = new MochaUI.Window(prefs);
+    this.window = nw;
     
     /*if(!focus) {
       MochaUI.Windows.indexLevel = oldIndexLevel;
@@ -79,15 +134,19 @@ var QMochaUIWindow = new Class({
     }*/
     
     /* HACK */
-    var toolbar = $(nw.options.id + "_toolbar");
+    if(toolbar) {
+      var toolbar = $(nw.options.id + "_toolbar");
+      toolbar.appendChild(this.form);
+    }
     this.titleText = $(nw.options.id + "_title");
     this.tabText = $(nw.options.id + "_dockTabText");
     
     /*alert(toolbar.parentNode.getStyle("background"));*/
     /*this.inputbox.setStyle("background", toolbar.parentNode.getStyle("background"));*/
-    toolbar.appendChild(this.form);
     this.windowObject = nw;
     
+    this.scroller = this.lines.parentNode.parentNode;
+    
     return;
 /*    
     if(type == WINDOW_CHANNEL) {
@@ -130,11 +189,9 @@ var QMochaUIWindow = new Class({
     while(t.firstChild)
       t.removeChild(t.firstChild);
 
-    Colourise(topic, t);
+    qwebirc.ui.Colourise(topic, t);
   },
   addLine: function(type, line, colour) {
-    this.parent(type, line, colour);
-    
     var e = new Element("div");
 
     if(colour) {
@@ -144,20 +201,19 @@ var QMochaUIWindow = new Class({
     } else {
       e.addClass("linestyle2");
     }
-    
-    if(type)
-      line = this.parentObject.theme.message(type, line);
-    
-    Colourise(IRCTimestamp(new Date()) + " " + line, e);
-    
     this.lastcolour = !this.lastcolour;
 
-    this.__scrollbottom(false, e);  
+    this.parent(type, line, colour, e, this.lines);
+  },
+  select: function() {
+    this.parent();
     
-    if(!this.active)
-      this.__setAlert(true);
+    if(this.inputbox)
+      this.inputbox.focus();
   },
-  __setAlert: function(state) {
+  setHilighted: function(state) {
+    this.parent(state);
+    
     if(state) {
       this.titleText.setStyle("color", "#ff0000");
       this.tabText.setStyle("background-color", "#ff0000");
@@ -166,95 +222,11 @@ var QMochaUIWindow = new Class({
       this.titleText.setStyle("color", null);
       this.tabText.setStyle("background-color", null);
       this.tabText.setStyle("color", null);
-    }
+    }    
   },
-  __scrollbottom: function(timed, element) {
-    var pe = this.lines.parentNode.parentNode;
-    //alert(pe);
-    var prev = pe.getScroll();
-    var prevbottom = pe.getScrollSize().y;
-    var prevsize = pe.getSize();
-    
-    /* scroll in bursts, else the browser gets really slow */
-    if(!timed) {
-      this.lines.appendChild(element);
-      if(this.scrolltimeout || (prev.y + prevsize.y == prevbottom)) {
-        if(this.scrolltimeout)
-          $clear(this.scrolltimeout);
-        this.scrolltimeout = this.__scrollbottom.delay(10, this, true);
-      }
-    } else {
-      pe.scrollTo(prev.x, pe.getScrollSize().y);
-      this.scrolltimeout = null;
-    }
-  },
-  select: function() {
+  close: function() {
     this.parent();
     
-    this.__setAlert(false);
-    
-    this.inputbox.focus();
-  }
-});
-
-var QMochaUI = new Class({
-  Extends: UI,
-    initialize: function(parentElement, theme) {
-    this.parent(parentElement, QMochaUIWindow, "mochaui");
-    this.theme = theme;
-    this.parentElement = parentElement;
-    
-    window.addEvent("domready", function() {
-      /* determine input size */
-      var l = new Element("input", {styles: {border: 0}});
-      this.parentElement.appendChild(l);
-      this.inputHeight = l.getSize().y;
-      this.parentElement.removeChild(l);
-      
-      MochaUI.Desktop = new MochaUI.Desktop();
-      MochaUI.Dock = new MochaUI.Dock({
-        dockPosition: "top"
-      });
-
-      MochaUI.Modal = new MochaUI.Modal();
-      MochaUI.options.useEffects = false;
-    }.bind(this));
-    
-    window.addEvent("unload", function() {
-      if(MochaUI)
-        MochaUI.garbageCleanUp();
-    });
-  },
-  postInitialize: function() {    
-    return;
-    this.tabs = new Element("div");
-    this.tabs.addClass("tabbar");
-    
-    this.parentElement.appendChild(this.tabs);
-    
-    this.container = new Element("div");
-    this.container.addClass("container");
-    
-    this.parentElement.appendChild(this.container);
-  
-    var form = new Element("form");
-    var inputbox = new Element("input");
-    inputbox.addClass("input");
-  
-    form.addEvent("submit", function(e) {
-      new Event(e).stop();
-    
-      this.getActiveWindow().client.exec(inputbox.value);
-      inputbox.value = "";
-    }.bind(this));
-    this.parentElement.appendChild(form);  
-    form.appendChild(inputbox);
-    inputbox.focus();
+    MochaUI.closeWindow(this.window.windowEl);
   },
-  loginBox: function(callbackfn, intialNickname, initialChannels) {
-    this.parent(function(options) {
-      this.postInitialize();
-      callbackfn(options);
-    }.bind(this), intialNickname, initialChannels);
-  }
 });