]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseuiwindow.js
Fix scrolling in alternate window bug.
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
1 var 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;
10 this.hilighted = false;
11 this.scrolltimer = null;
12 this.commandhistory = this.parentObject.commandhistory;
13 this.scrolleddown = false;
14 //new CommandHistory();
15 },
16 updateNickList: function(nicks) {
17 },
18 updateTopic: function(topic) {
19 },
20 close: function() {
21 if($defined(this.scrolltimer)) {
22 $clear(this.scrolltimer);
23 this.scrolltimer = null;
24 }
25
26 this.parentObject.__closed(this);
27 this.fireEvent("close", this);
28 },
29 select: function() {
30 this.active = true;
31 this.parentObject.__setActiveWindow(this);
32 if(this.hilighted)
33 this.setHilighted(false);
34 if(this.scrolleddown)
35 this.__scrollToBottom();
36 },
37 deselect: function() {
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
45 this.active = false;
46 },
47 addLine: function(type, line, colour, element, parent, scrollparent) {
48 if(!this.active && !this.hilighted)
49 this.setHilighted(true);
50
51 if(type)
52 line = this.parentObject.theme.message(type, line);
53
54 Colourise(IRCTimestamp(new Date()) + " " + line, element);
55
56 this.scrollAdd(element);
57 },
58 errorMessage: function(message) {
59 this.addLine("", message, "red");
60 },
61 setHilighted: function(state) {
62 this.hilighted = state;
63 },
64 __scrolledDown: function() {
65 if(this.scrolltimer)
66 return true;
67
68 var parent = this.lines;
69
70 var prev = parent.getScroll();
71 var prevbottom = parent.getScrollSize().y;
72 var prevsize = parent.getSize();
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;
87
88 /* scroll in bursts, else the browser gets really slow */
89 if($defined(element)) {
90 var sd = this.__scrolledDown();
91 parent.appendChild(element);
92 if(sd) {
93 if(this.scrolltimer)
94 $clear(this.scrolltimer);
95 this.scrolltimer = this.scrollAdd.delay(50, this, [null]);
96 }
97 } else {
98 this.__scrollToBottom();
99 this.scrolltimer = null;
100 }
101 },
102 historyExec: function(line) {
103 this.commandhistory.addLine(line);
104 this.client.exec(line);
105 }
106 });