]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/mochaui.js
Rework old UI's to support custom/connect windows.
[irc/quakenet/qwebirc.git] / js / ui / mochaui.js
index 3a4358959c923051e75dc7506b19d298460d95f5..710e0732303f61c8325f7516ee9726d92e0de6b9 100644 (file)
@@ -6,48 +6,90 @@ var QMochaUIWindow = new Class({
 
     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.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 toolbar = type != WINDOW_CUSTOM && type != 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: 500,
+      width: 800,
       height: 400,
       title: name,
       footerHeight: 0,
-      toolbar: true,
       container: $("pageWrapper"),
       toolbarHeight: parentObject.inputHeight,
       toolbarPosition: "bottom",
       toolbarContent: "",
+      //toolbarURL: "",
+      toolbarLoadMethod: "html",
       content: this.lines,
+      minimized: true,
+      addClass: "hidenewwin",
       onFocus: function() {
         parentObject.selectWindow(this);
       }.bind(this),
       onClose: function() {
         if(type == WINDOW_CHANNEL)
           this.client.exec("/PART " + name);
-
         this.close();
       }.bind(this)
     };
     
-    if(type == WINDOW_STATUS)
-      prefs.closable = false;
+    prefs.toolbar = toolbar;
+    prefs.closable = type != WINDOW_STATUS && type != WINDOW_CONNECT;
     
+    /* HACK */
+/*    var oldIndexLevel = MochaUI.Windows.indexLevel;
+    
+    var focus = false;
+    var oldfocus = MochaUI.focusWindow;
+    if(!focus) {
+      MochaUI.Windows.indexLevel = 0;
+      MochaUI.focusWindow = null;
+    }
+  */  
     var nw = new MochaUI.Window(prefs);
+    this.window = nw;
+    
+    /*if(!focus) {
+      MochaUI.Windows.indexLevel = oldIndexLevel;
+      MochaUI.focusWindow = oldfocus;
+    }*/
+    
     /* HACK */
-    var toolbar = $(nw.options.id + "_toolbar");
-    toolbar.appendChild(this.form);
+    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"));*/
+    this.windowObject = nw;
+    
+    this.scroller = this.lines.parentNode.parentNode;
     
     return;
 /*    
@@ -94,8 +136,6 @@ var QMochaUIWindow = new Class({
     Colourise(topic, t);
   },
   addLine: function(type, line, colour) {
-    this.parent(type, line, colour);
-    
     var e = new Element("div");
 
     if(colour) {
@@ -105,31 +145,38 @@ 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.parent(type, line, colour, e, this.lines);
+  },
+  select: function() {
+    this.parent();
     
-    var pe = this.lines.parentNode.parentNode;
+    if(this.inputbox)
+      this.inputbox.focus();
+  },
+  setHilighted: function(state) {
+    this.parent(state);
     
-    var prev = pe.getScroll();
-    var prevbottom = pe.getScrollSize().y;
-    var prevsize = pe.getSize();
-    this.lines.appendChild(e);
+    if(state) {
+      this.titleText.setStyle("color", "#ff0000");
+      this.tabText.setStyle("background-color", "#ff0000");
+      this.tabText.setStyle("color", "#000000");
+    } else {
+      this.titleText.setStyle("color", null);
+      this.tabText.setStyle("background-color", null);
+      this.tabText.setStyle("color", null);
+    }    
+  },
+  close: function() {
+    this.parent();
     
-    if(prev.y + prevsize.y == prevbottom)
-      pe.scrollTo(prev.x, pe.getScrollSize().y);
-      
-    if(!this.active)
-      this.lines.showLoadingIcon();
-  }
+    MochaUI.closeWindow(this.window.windowEl);
+  },
 });
 
 var QMochaUI = new Class({
-  Extends: UI,
+  Extends: NewLoginUI,
     initialize: function(parentElement, theme) {
     this.parent(parentElement, QMochaUIWindow, "mochaui");
     this.theme = theme;
@@ -181,11 +228,5 @@ var QMochaUI = new Class({
     this.parentElement.appendChild(form);  
     form.appendChild(inputbox);
     inputbox.focus();
-  },
-  loginBox: function(callbackfn, intialNickname, initialChannels) {
-    this.parent(function(options) {
-      this.postInitialize();
-      callbackfn(options);
-    }.bind(this), intialNickname, initialChannels);
   }
 });