]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/baseuiwindow.js
Fixes issue #127, seems I never implemented this!
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
index 1bffbbfeb6aefe4a8cca86fbbd877c68578ea250..8c2f73c5d392944184d952220858f16b1e8109be 100644 (file)
@@ -3,6 +3,8 @@ qwebirc.ui.HILIGHT_ACTIVITY = 1;
 qwebirc.ui.HILIGHT_SPEECH = 2;
 qwebirc.ui.HILIGHT_US = 3;
 
+qwebirc.ui.WINDOW_LASTLINE = qwebirc.ui.WINDOW_QUERY | qwebirc.ui.WINDOW_MESSAGES | qwebirc.ui.WINDOW_CHANNEL | qwebirc.ui.WINDOW_STATUS;
+
 qwebirc.ui.Window = new Class({
   Implements: [Events],
   initialize: function(parentObject, client, type, name, identifier) {
@@ -19,9 +21,14 @@ qwebirc.ui.Window = new Class({
     this.scrollpos = null;
     this.lastNickHash = {};
     this.lastSelected = null;
+    this.subWindow = null;
     this.closed = false;
-  },
-  updateNickList: function(nicks) {
+    
+    if(this.type & qwebirc.ui.WINDOW_LASTLINE) {
+      this.lastPositionLine = new Element("hr");
+      this.lastPositionLine.addClass("lastpos");
+      this.lastPositionLineInserted = false;
+    }
   },
   updateTopic: function(topic, element)  {
     qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
@@ -37,22 +44,40 @@ qwebirc.ui.Window = new Class({
     this.parentObject.__closed(this);
     this.fireEvent("close", this);
   },
+  subEvent: function(event) {
+    if($defined(this.subWindow))
+      this.subWindow.fireEvent(event);
+  },
+  setSubWindow: function(window) {
+    this.subWindow = window;
+  },
   select: function() {
+    if(this.lastPositionLineInserted && !this.parentObject.uiOptions.LASTPOS_LINE) {
+      this.lines.removeChild(this.lastPositionLine);
+      this.lastPositionLineInserted = false;
+    }
+  
     this.active = true;
     this.parentObject.__setActiveWindow(this);
     if(this.hilighted)
       this.setHilighted(qwebirc.ui.HILIGHT_NONE);
-      
+
+    this.subEvent("select");      
     this.resetScrollPos();
     this.lastSelected = new Date();
   },
   deselect: function() {
+    this.subEvent("deselect");
+    
     this.setScrollPos();
     if($defined(this.scrolltimer)) {
       $clear(this.scrolltimer);
       this.scrolltimer = null;
     }
 
+    if(this.type & qwebirc.ui.WINDOW_LASTLINE)
+      this.replaceLastPositionLine();
+    
     this.active = false;
   },
   resetScrollPos: function() {
@@ -82,12 +107,14 @@ qwebirc.ui.Window = new Class({
           } else {
             hilight = qwebirc.ui.HILIGHT_US;
             this.parentObject.beep();
+            this.parentObject.flash();
           }
         }
         if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) {
           lhilight = true;
           hilight = qwebirc.ui.HILIGHT_US;
           this.parentObject.beep();
+          this.parentObject.flash();
         } else if(hilight != qwebirc.ui.HILIGHT_US) {
           hilight = qwebirc.ui.HILIGHT_SPEECH;
         }
@@ -104,10 +131,10 @@ qwebirc.ui.Window = new Class({
     this.scrollAdd(element);
   },
   errorMessage: function(message) {
-    this.addLine("", message, "#FF6347");
+    this.addLine("", message, "warncolour");
   },
   infoMessage: function(message) {
-    this.addLine("", message, "#87CEFA");
+    this.addLine("", message, "infocolour");
   },
   setHilighted: function(state) {
     if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted)
@@ -121,13 +148,16 @@ qwebirc.ui.Window = new Class({
     
     var prev = parent.getScroll();
     var prevbottom = parent.getScrollSize().y;
-    var prevsize = parent.getSize();
-    
-    /* fixes an IE bug */
-    if(prevbottom < prevsize.y)
-      prevbottom = prevsize.y;
+    var prevheight = parent.clientHeight;
+
+    /*
+     * fixes an IE bug: the scrollheight is less than the actual height
+     * when the div isn't full
+     */
+    if(prevbottom < prevheight)
+      prevbottom = prevheight;
       
-    return prev.y + prevsize.y == prevbottom;
+    return prev.y + prevheight == prevbottom;
   },
   getScrollParent: function() {
     var scrollparent = this.lines;
@@ -194,5 +224,30 @@ qwebirc.ui.Window = new Class({
   historyExec: function(line) {
     this.commandhistory.addLine(line);
     this.client.exec(line);
+  },
+  focusChange: function(newValue) {
+    if(newValue == true || !(this.type & qwebirc.ui.WINDOW_LASTLINE))
+      return;
+    
+    this.replaceLastPositionLine();
+  },
+  replaceLastPositionLine: function() {
+    if(this.parentObject.uiOptions.LASTPOS_LINE) {
+      if(!this.lastPositionLineInserted) {
+        this.scrollAdd(this.lastPositionLine);
+      } else if(this.lines.lastChild != this.lastPositionLine) {
+        try {
+          this.lines.removeChild(this.lastPositionLine);
+        } catch(e) {
+          /* IGNORE, /clear removes lastPositionLine from the dom without resetting it. */
+        }
+        this.scrollAdd(this.lastPositionLine);
+      }
+    } else {
+      if(this.lastPositionLineInserted)
+        this.lines.removeChild(this.lastPositionLine);
+    }
+    
+    this.lastPositionLineInserted = this.parentObject.uiOptions.LASTPOS_LINE;
   }
 });