X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/2afb847b7343aaa87943f173498e7e8afe0f5dc9..ea29e3d77bb6b6f11545dd02a43883def07ea869:/js/ui/baseuiwindow.js diff --git a/js/ui/baseuiwindow.js b/js/ui/baseuiwindow.js index 8c2f73c..22200ad 100644 --- a/js/ui/baseuiwindow.js +++ b/js/ui/baseuiwindow.js @@ -3,6 +3,8 @@ qwebirc.ui.HILIGHT_ACTIVITY = 1; qwebirc.ui.HILIGHT_SPEECH = 2; qwebirc.ui.HILIGHT_US = 3; +qwebirc.ui.MAXIMUM_LINES_PER_WINDOW = 1000; + 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({ @@ -19,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; @@ -127,14 +129,23 @@ qwebirc.ui.Window = new Class({ if(type) line = this.parentObject.theme.message(type, line, lhilight); - qwebirc.ui.Colourise(qwebirc.irc.IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); + var tsE = document.createElement("span"); + tsE.className = "timestamp"; + tsE.appendChild(document.createTextNode(qwebirc.irc.IRCTimestamp(new Date()) + " ")); + element.appendChild(tsE); + + qwebirc.ui.Colourise(line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this); this.scrollAdd(element); }, errorMessage: function(message) { this.addLine("", message, "warncolour"); }, - infoMessage: function(message) { - this.addLine("", message, "infocolour"); + infoMessage: function(type, message) { + if(message === undefined) { + this.addLine("", type, "infocolour"); + } else { + this.addLine(type, message, "infocolour"); + } }, setHilighted: function(state) { if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted) @@ -145,19 +156,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; @@ -182,37 +193,38 @@ qwebirc.ui.Window = new Class({ if($defined(element)) { var sd = this.scrolledDown(); parent.appendChild(element); - if(sd) { - if(this.scrolltimer) - $clear(this.scrolltimer); + if(parent.childNodes.length > qwebirc.ui.MAXIMUM_LINES_PER_WINDOW) + parent.removeChild(parent.firstChild); + + if(sd && !this.scrollTimer) this.scrolltimer = this.scrollAdd.delay(50, this, [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