]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/qui.js
IE fixes.
[irc/quakenet/qwebirc.git] / js / ui / qui.js
index 27df4f3a67032c7375172d3460283a4c6d478f0e..2206107d2a704efbc2135bcb3f2378eac6d0fce8 100644 (file)
@@ -7,7 +7,11 @@ qwebirc.ui.QUI = new Class({
   },
   postInitialize: function() {
     this.qjsui = new qwebirc.ui.QUI.JSUI("qwebirc-qui", this.parentElement);
-    
+    this.qjsui.addEvent("reflow", function() {
+      var w = this.getActiveWindow();
+      if($defined(w))
+        w.onResize();
+    }.bind(this));
     this.qjsui.top.addClass("tabbar");
     
     this.qjsui.bottom.addClass("input");
@@ -23,6 +27,19 @@ qwebirc.ui.QUI = new Class({
     this.input = this.qjsui.bottom;
     this.reflow = this.qjsui.reflow.bind(this.qjsui);
     
+    this.tabs.addEvent("mousewheel", function(x) {
+      var event = new Event(x);
+      
+      /* up */
+      if(event.wheel > 0) {
+        this.nextWindow();
+      } else if(event.wheel < 0) {
+        /* down */
+        this.prevWindow();        
+      }
+      event.stop();
+    }.bind(this));
+    
     this.createInput();
     this.reflow();
   },
@@ -41,22 +58,33 @@ qwebirc.ui.QUI = new Class({
       if(inputbox.value == "")
         return;
         
+      this.resetTabComplete();
       this.getActiveWindow().historyExec(inputbox.value);
       inputbox.value = "";
     }.bind(this));
     
+    inputbox.addEvent("focus", this.resetTabComplete.bind(this));
+    inputbox.addEvent("mousedown", this.resetTabComplete.bind(this));
+    
     inputbox.addEvent("keydown", function(e) {
       var resultfn;
       var cvalue = inputbox.value;
-
+      
       if(e.key == "up") {
         resultfn = this.commandhistory.upLine;
       } else if(e.key == "down") {
         resultfn = this.commandhistory.downLine;
+      } else if(e.key == "tab") {
+        new Event(e).stop();
+        this.tabComplete(inputbox);
+        return;
       } else {
+        /* ideally alt and other keys wouldn't break this */
+        this.resetTabComplete();
         return;
       }
       
+      this.resetTabComplete();
       if((cvalue != "") && (this.lastcvalue != cvalue))
         this.commandhistory.addLine(cvalue, true);
       
@@ -89,6 +117,7 @@ qwebirc.ui.QUI = new Class({
 });
 
 qwebirc.ui.QUI.JSUI = new Class({
+  Implements: [Events],
   initialize: function(class_, parent, sizer) {
     this.parent = parent;
     this.sizer = $defined(sizer)?sizer:parent;
@@ -174,6 +203,7 @@ qwebirc.ui.QUI.JSUI = new Class({
     right.setStyle("left", mwidth + "px");
     
     bottom.setStyle("top", (docsize.y - bottomsize.y) + "px");
+    this.fireEvent("reflow");
   },
   showChannel: function(state) {
     var display = "none";
@@ -203,6 +233,10 @@ qwebirc.ui.QUI.Window = new Class({
     this.tab.appendText(name);
     this.tab.addEvent("click", function(e) {
       new Event(e).stop();
+      
+      if(this.closed)
+        return;
+        
       parentObject.selectWindow(this);
     }.bind(this));
     
@@ -210,13 +244,29 @@ qwebirc.ui.QUI.Window = new Class({
       var tabclose = new Element("span");
       tabclose.set("text", "X");
       tabclose.addClass("tabclose");
-      tabclose.addEvent("click", function(e) {
+      var close = function(e) {
         new Event(e).stop();
         
+        if(this.closed)
+          return;
+          
         if(type == qwebirc.ui.WINDOW_CHANNEL)
           this.client.exec("/PART " + name);
 
         this.close();
+        
+        parentObject.inputbox.focus();
+      }.bind(this);
+      
+      tabclose.addEvent("click", close);
+      this.tab.addEvent("mouseup", function(e) {
+        var button = 1;
+        
+        if(Browser.Engine.trident)
+          button = 4;
+
+        if(e.event.button == button)
+          close(e);
       }.bind(this));
       
       this.tab.appendChild(tabclose);
@@ -228,6 +278,7 @@ qwebirc.ui.QUI.Window = new Class({
     
     this.lines.addEvent("scroll", function() {
       this.scrolleddown = this.scrolledDown();
+      this.scrollpos = this.getScrollParent().getScroll();
     }.bind(this));
     
     if(type == qwebirc.ui.WINDOW_CHANNEL) {
@@ -241,12 +292,7 @@ qwebirc.ui.QUI.Window = new Class({
       this.nicklist = new Element("div");
       this.nicklist.addClass("nicklist");
       this.nicklist.addClass("tab-invisible");
-      this.nicklist.addEvent("click", function(x) {
-        if(this.prevNick) {
-          this.prevNick.removeClass("selected");
-          this.prevNick = null;
-        }
-      }.bind(this));
+      this.nicklist.addEvent("click", this.removePrevMenu.bind(this));
       this.parentObject.qjsui.applyClasses("nicklist", this.nicklist);
     }
     
@@ -260,8 +306,63 @@ qwebirc.ui.QUI.Window = new Class({
     this.parentObject.reflow();
   },
   onResize: function() {
-    if(this.scrolleddown)
-      this.scrollToBottom();
+    if(this.scrolleddown) {
+      if(Browser.Engine.trident) {
+        this.scrollToBottom.delay(5, this);
+      } else {
+        this.scrollToBottom();
+      }
+    } else if($defined(this.scrollpos)) {
+      if(Browser.Engine.trident) {
+        this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y);
+      } else {
+        this.getScrollParent().scrollTo.delay(5, this, [this.scrollpos.x, this.scrollpos.y]);
+      }
+    }
+  },
+  createMenu: function(nick, parent) {
+    var e = new Element("div");
+    parent.appendChild(e);
+    e.addClass("menu");
+    
+    qwebirc.ui.MENU_ITEMS.forEach(function(x) {
+      var e2 = new Element("a");
+      e.appendChild(e2);
+      
+      e2.href = "#";
+      e2.set("text", "- " + x[0]);
+      
+      e2.addEvent("focus", function() { this.blur() }.bind(e2));
+      e2.addEvent("click", function(ev) { new Event(ev.stop()); this.menuClick(x[1]); }.bind(this));
+    }.bind(this));
+    return e;
+  },
+  menuClick: function(fn) {
+    /*
+    this.prevNick.removeChild(this.prevNick.menu);
+    this.prevNick.menu = null;
+    */
+    fn.bind(this)(this.prevNick.realNick);
+    this.removePrevMenu();
+  },
+  moveMenuClass: function() {
+    if(!this.prevNick)
+      return;
+    if(this.nicklist.firstChild == this.prevNick) {
+      this.prevNick.removeClass("selected-middle");
+    } else {
+      this.prevNick.addClass("selected-middle");
+    }
+  },
+  removePrevMenu: function() {
+    if(!this.prevNick)
+      return;
+      
+    this.prevNick.removeClass("selected");
+    this.prevNick.removeClass("selected-middle");
+    if(this.prevNick.menu)
+      this.prevNick.removeChild(this.prevNick.menu);
+    this.prevNick = null;
   },
   nickListAdd: function(nick, position) {
     var e = new Element("a");
@@ -273,10 +374,16 @@ qwebirc.ui.QUI.Window = new Class({
     e.realNick = this.client.stripPrefix(nick);
     
     e.addEvent("click", function(x) {
-      if(this.prevNick)
-        this.prevNick.removeClass("selected");
+      if(this.prevNick == e) {
+        this.removePrevMenu();
+        return;
+      }
+      
+      this.removePrevMenu();
       this.prevNick = e;
       e.addClass("selected");
+      this.moveMenuClass();
+      e.menu = this.createMenu(x.realNick, e);
       new Event(x).stop();
     }.bind(this));
     e.addEvent("dblclick", function(x) {
@@ -285,11 +392,12 @@ qwebirc.ui.QUI.Window = new Class({
     }.bind(this));
     
     e.addEvent("focus", function() { this.blur() }.bind(e));
-    
+    this.moveMenuClass();
     return e;
   },
   nickListRemove: function(nick, stored) {
     this.nicklist.removeChild(stored);
+    this.moveMenuClass();
   },
   updateTopic: function(topic) {
     var t = this.topic;