]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseuiwindow.js
Fix scrolling in alternate window bug.
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
CommitLineData
94b18192
CP
1var UIWindow = new Class({
2 Implements: [Events],
3 initialize: function(parentObject, client, type, name, identifier) {
4 this.parentObject = parentObject;
5 this.type = type;
6 this.name = name;
7 this.active = false;
8 this.client = client;
9 this.identifier = identifier;
381fddfd
CP
10 this.hilighted = false;
11 this.scrolltimer = null;
9b63b053 12 this.commandhistory = this.parentObject.commandhistory;
7c633700 13 this.scrolleddown = false;
9b63b053 14 //new CommandHistory();
94b18192
CP
15 },
16 updateNickList: function(nicks) {
17 },
18 updateTopic: function(topic) {
19 },
20 close: function() {
381fddfd
CP
21 if($defined(this.scrolltimer)) {
22 $clear(this.scrolltimer);
23 this.scrolltimer = null;
24 }
25
94b18192
CP
26 this.parentObject.__closed(this);
27 this.fireEvent("close", this);
28 },
29 select: function() {
30 this.active = true;
31 this.parentObject.__setActiveWindow(this);
381fddfd 32 if(this.hilighted)
349b99ed 33 this.setHilighted(false);
7c633700
CP
34 if(this.scrolleddown)
35 this.__scrollToBottom();
94b18192
CP
36 },
37 deselect: function() {
7c633700
CP
38 if(!this.parentObject.singleWindow)
39 this.scrolleddown = this.__scrolledDown();
40 if($defined(this.scrolltimer)) {
41 $clear(this.scrolltimer);
42 this.scrolltimer = null;
43 }
44
94b18192
CP
45 this.active = false;
46 },
381fddfd
CP
47 addLine: function(type, line, colour, element, parent, scrollparent) {
48 if(!this.active && !this.hilighted)
349b99ed
CP
49 this.setHilighted(true);
50
381fddfd
CP
51 if(type)
52 line = this.parentObject.theme.message(type, line);
53
54 Colourise(IRCTimestamp(new Date()) + " " + line, element);
55
56 this.scrollAdd(element);
94b18192
CP
57 },
58 errorMessage: function(message) {
59 this.addLine("", message, "red");
381fddfd
CP
60 },
61 setHilighted: function(state) {
62 this.hilighted = state;
63 },
7c633700
CP
64 __scrolledDown: function() {
65 if(this.scrolltimer)
66 return true;
67
381fddfd 68 var parent = this.lines;
381fddfd 69
381fddfd
CP
70 var prev = parent.getScroll();
71 var prevbottom = parent.getScrollSize().y;
72 var prevsize = parent.getSize();
7c633700
CP
73 //alert("1: " + (prev.y + prevsize.y) + " 2:" + prevbottom);
74 return prev.y + prevsize.y == prevbottom;
75 },
76 __scrollToBottom: function() {
77 var parent = this.lines;
78 var scrollparent = parent;
79
80 if($defined(this.scroller))
81 scrollparent = this.scroller;
82
83 scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y);
84 },
85 scrollAdd: function(element) {
86 var parent = this.lines;
381fddfd
CP
87
88 /* scroll in bursts, else the browser gets really slow */
89 if($defined(element)) {
7c633700 90 var sd = this.__scrolledDown();
381fddfd 91 parent.appendChild(element);
7c633700 92 if(sd) {
381fddfd
CP
93 if(this.scrolltimer)
94 $clear(this.scrolltimer);
7c633700 95 this.scrolltimer = this.scrollAdd.delay(50, this, [null]);
381fddfd
CP
96 }
97 } else {
7c633700 98 this.__scrollToBottom();
381fddfd
CP
99 this.scrolltimer = null;
100 }
9b63b053
CP
101 },
102 historyExec: function(line) {
103 this.commandhistory.addLine(line);
104 this.client.exec(line);
94b18192
CP
105 }
106});