]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/baseuiwindow.js
iframes should not have borders -- breaks page layout
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
index f348beb27281e141280f149000dd6c5becf2517a..a31338fd265a354ea5792af062721a6a2d8f2e1e 100644 (file)
@@ -21,7 +21,7 @@ qwebirc.ui.Window = new Class({
     this.commandhistory = this.parentObject.commandhistory;
     this.scrolleddown = true;
     this.scrollpos = null;
-    this.lastNickHash = {};
+    this.lastNickHash = new QHash();
     this.lastSelected = null;
     this.subWindow = null;
     this.closed = false;
@@ -33,7 +33,7 @@ qwebirc.ui.Window = new Class({
     }
   },
   updateTopic: function(topic, element)  {
-    qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
+    qwebirc.ui.Colourise(topic, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
   },
   close: function() {
     this.closed = true;
@@ -98,28 +98,38 @@ qwebirc.ui.Window = new Class({
   addLine: function(type, line, colour, element) {
     var hilight = qwebirc.ui.HILIGHT_NONE;
     var lhilight = false;
-    
+
     if(type) {
       hilight = qwebirc.ui.HILIGHT_ACTIVITY;
-      
+
       if(type.match(/(NOTICE|ACTION|MSG)$/)) {
-        if(this.type == qwebirc.ui.WINDOW_QUERY || this.type == qwebirc.ui.WINDOW_MESSAGES) {
-          if(type.match(/^OUR/) || type.match(/NOTICE$/)) {
-            hilight = qwebirc.ui.HILIGHT_ACTIVITY;
+        var message = $defined(line) ? line["m"] : null;
+
+        /* https://dl.dropboxusercontent.com/u/180911/notify.png */
+        if(type.match(/^OUR/)) {
+          if(type.match(/NOTICE$/)) {
+            /* default */
           } else {
-            hilight = qwebirc.ui.HILIGHT_US;
-            this.parentObject.beep();
-            this.parentObject.flash();
+            hilight = qwebirc.ui.HILIGHT_SPEECH;
           }
-        }
-        if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) {
+        } else if(this.client.hilightController.match(message)) {
+          hilight = qwebirc.ui.HILIGHT_US;
           lhilight = true;
+        } else if(type.match(/NOTICE$/)) {
+          /* default */
+        } else if(this.type == qwebirc.ui.WINDOW_QUERY || this.type == qwebirc.ui.WINDOW_MESSAGES) {
           hilight = qwebirc.ui.HILIGHT_US;
-          this.parentObject.beep();
-          this.parentObject.flash();
-        } else if(hilight != qwebirc.ui.HILIGHT_US) {
+        } else {
           hilight = qwebirc.ui.HILIGHT_SPEECH;
         }
+
+        if(hilight == qwebirc.ui.HILIGHT_US) {
+          var title = this.parentObject.theme.message("NOTIFY" + type + "TITLE", line, false);
+          var body = this.parentObject.theme.message("NOTIFY" + type + "BODY", line, false);
+          var selectMe = function() { this.parentObject.selectWindow(this); }.bind(this);
+
+          this.parentObject.notify(title, body, selectMe);
+        }
       }
     }
 
@@ -156,19 +166,19 @@ qwebirc.ui.Window = new Class({
       return true;
       
     var parent = this.lines;
-    
-    var prev = parent.getScroll();
-    var prevbottom = parent.getScrollSize().y;
-    var prevheight = parent.clientHeight;
+
+    var scrollPos = parent.getScroll().y;
+    var linesHeight = parent.getScrollSize().y;
+    var windowHeight = 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 + prevheight == prevbottom;
+    if(linesHeight < windowHeight)
+      linesHeight = windowHeight;
+
+    return scrollPos + windowHeight >= linesHeight - 3; /* window of error */
   },
   getScrollParent: function() {
     var scrollparent = this.lines;
@@ -195,40 +205,36 @@ qwebirc.ui.Window = new Class({
       parent.appendChild(element);
       if(parent.childNodes.length > qwebirc.ui.MAXIMUM_LINES_PER_WINDOW)
         parent.removeChild(parent.firstChild);
-      if(sd) {
-        if(this.scrolltimer)
-          $clear(this.scrolltimer);
+
+      if(sd && !this.scrollTimer)
         this.scrolltimer = this.scrollAdd.delay(50, this, [null]);
-      } else {
-        this.scrollToBottom();
-        this.scrolltimer = null;
-      }
     } else {
       this.scrollToBottom();
       this.scrolltimer = null;
     }
   },
   updateNickList: function(nicks) {
-    var nickHash = {}, present = {};
+    var nickHash = new QHash(), present = new QSet();
     var added = [];
     var lnh = this.lastNickHash;
     
     for(var i=0;i<nicks.length;i++)
-      present[nicks[i]] = 1;
-    
-    for(var k in lnh)
-      if(!present[k])
-        this.nickListRemove(k, lnh[k]);
-        
+      present.add(nicks[i]);
+
+    lnh.each(function(k, v) {
+      if(!present.contains(k))
+        this.nickListRemove(k, v);
+    }, this);
+
     for(var i=0;i<nicks.length;i++) {
       var n = nicks[i];
-      var l = lnh[n];
+      var l = lnh.get(n);
       if(!l) {
         l = this.nickListAdd(n, i);
         if(!l)
           l = 1;
       }
-      nickHash[n] = l;
+      nickHash.put(n, l);
     }
     
     this.lastNickHash = nickHash;
@@ -249,6 +255,9 @@ qwebirc.ui.Window = new Class({
   },
   replaceLastPositionLine: function() {
     if(this.parentObject.uiOptions.LASTPOS_LINE) {
+      if(!this.scrolledDown())
+        return;
+
       if(!this.lastPositionLineInserted) {
         this.scrollAdd(this.lastPositionLine);
       } else if(this.lines.lastChild != this.lastPositionLine) {