]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseuiwindow.js
Scrolling now works in IE.
[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;
25be5960 13 this.scrolleddown = true;
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 34 if(this.scrolleddown)
25be5960 35 this.scrollToBottom();
94b18192
CP
36 },
37 deselect: function() {
7c633700 38 if(!this.parentObject.singleWindow)
25be5960 39 this.scrolleddown = this.scrolledDown();
7c633700
CP
40 if($defined(this.scrolltimer)) {
41 $clear(this.scrolltimer);
42 this.scrolltimer = null;
43 }
44
94b18192
CP
45 this.active = false;
46 },
30bd2620 47 addLine: function(type, line, colour, element) {
381fddfd 48 if(!this.active && !this.hilighted)
349b99ed 49 this.setHilighted(true);
381fddfd
CP
50 if(type)
51 line = this.parentObject.theme.message(type, line);
52
8af49135 53 Colourise(IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject));
381fddfd
CP
54
55 this.scrollAdd(element);
94b18192
CP
56 },
57 errorMessage: function(message) {
58 this.addLine("", message, "red");
381fddfd
CP
59 },
60 setHilighted: function(state) {
61 this.hilighted = state;
62 },
25be5960 63 scrolledDown: function() {
7c633700
CP
64 if(this.scrolltimer)
65 return true;
66
381fddfd 67 var parent = this.lines;
381fddfd 68
381fddfd
CP
69 var prev = parent.getScroll();
70 var prevbottom = parent.getScrollSize().y;
71 var prevsize = parent.getSize();
25be5960 72
fccb1dac
CP
73 /* fixes an IE bug */
74 if(prevbottom < prevsize.y)
75 prevbottom = prevsize.y;
76
7c633700
CP
77 return prev.y + prevsize.y == prevbottom;
78 },
25be5960 79 scrollToBottom: function() {
7c633700
CP
80 var parent = this.lines;
81 var scrollparent = parent;
82
83 if($defined(this.scroller))
84 scrollparent = this.scroller;
85
86 scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y);
87 },
88 scrollAdd: function(element) {
89 var parent = this.lines;
381fddfd
CP
90
91 /* scroll in bursts, else the browser gets really slow */
92 if($defined(element)) {
25be5960 93 var sd = this.scrolledDown();
381fddfd 94 parent.appendChild(element);
7c633700 95 if(sd) {
381fddfd
CP
96 if(this.scrolltimer)
97 $clear(this.scrolltimer);
7c633700 98 this.scrolltimer = this.scrollAdd.delay(50, this, [null]);
381fddfd
CP
99 }
100 } else {
25be5960 101 this.scrollToBottom();
381fddfd
CP
102 this.scrolltimer = null;
103 }
9b63b053
CP
104 },
105 historyExec: function(line) {
106 this.commandhistory.addLine(line);
107 this.client.exec(line);
94b18192
CP
108 }
109});