]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/baseuiwindow.js
Fixes issue 38 (autoscroll breaks on lines that display a horizontal scrollbar).
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
index 90e8b0f244db900a5ac5924da4379d18eac3e678..8c2f73c5d392944184d952220858f16b1e8109be 100644 (file)
@@ -75,15 +75,8 @@ qwebirc.ui.Window = new Class({
       this.scrolltimer = null;
     }
 
-    if(this.type & qwebirc.ui.WINDOW_LASTLINE) {
-      if(this.lastPositionLineInserted)
-        this.lines.removeChild(this.lastPositionLine);
-      
-      if(this.parentObject.uiOptions.LASTPOS_LINE)
-        this.lines.appendChild(this.lastPositionLine);
-     
-      this.lastPositionLineInserted = this.parentObject.uiOptions.LASTPOS_LINE;
-    }
+    if(this.type & qwebirc.ui.WINDOW_LASTLINE)
+      this.replaceLastPositionLine();
     
     this.active = false;
   },
@@ -155,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;
@@ -228,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;
+  }
 });