X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/326478c2a6e0551be206581287823f5053266461..2db47312ba944bdc5e4dd427e42fde9435ec6fa0:/js/ui/baseuiwindow.js diff --git a/js/ui/baseuiwindow.js b/js/ui/baseuiwindow.js index e9a448b..5369d1a 100644 --- a/js/ui/baseuiwindow.js +++ b/js/ui/baseuiwindow.js @@ -3,6 +3,10 @@ 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({ Implements: [Events], initialize: function(parentObject, client, type, name, identifier) { @@ -21,6 +25,12 @@ qwebirc.ui.Window = new Class({ this.lastSelected = null; this.subWindow = null; this.closed = false; + + 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); @@ -44,6 +54,11 @@ qwebirc.ui.Window = new Class({ 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) @@ -62,6 +77,9 @@ qwebirc.ui.Window = new Class({ this.scrolltimer = null; } + if(this.type & qwebirc.ui.WINDOW_LASTLINE) + this.replaceLastPositionLine(); + this.active = false; }, resetScrollPos: function() { @@ -111,7 +129,12 @@ 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) { @@ -132,13 +155,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; @@ -163,10 +189,15 @@ qwebirc.ui.Window = new Class({ if($defined(element)) { var sd = this.scrolledDown(); 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); this.scrolltimer = this.scrollAdd.delay(50, this, [null]); + } else { + this.scrollToBottom(); + this.scrolltimer = null; } } else { this.scrollToBottom(); @@ -205,5 +236,32 @@ 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; + }, + rename: function(name) { + } });