]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseuiwindow.js
Inheritance tidying + tidying!
[irc/quakenet/qwebirc.git] / js / ui / baseuiwindow.js
1 qwebirc.ui.HILIGHT_NONE = 0;
2 qwebirc.ui.HILIGHT_ACTIVITY = 1;
3 qwebirc.ui.HILIGHT_SPEECH = 2;
4 qwebirc.ui.HILIGHT_US = 3;
5
6 qwebirc.ui.Window = new Class({
7 Implements: [Events],
8 initialize: function(parentObject, client, type, name, identifier) {
9 this.parentObject = parentObject;
10 this.type = type;
11 this.name = name;
12 this.active = false;
13 this.client = client;
14 this.identifier = identifier;
15 this.hilighted = qwebirc.ui.HILIGHT_NONE;
16 this.scrolltimer = null;
17 this.commandhistory = this.parentObject.commandhistory;
18 this.scrolleddown = true;
19 this.scrollpos = null;
20 this.lastNickHash = {};
21 this.lastSelected = null;
22 this.subWindow = null;
23 this.closed = false;
24 },
25 updateTopic: function(topic, element) {
26 qwebirc.ui.Colourise("[" + topic + "]", element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
27 },
28 close: function() {
29 this.closed = true;
30
31 if($defined(this.scrolltimer)) {
32 $clear(this.scrolltimer);
33 this.scrolltimer = null;
34 }
35
36 this.parentObject.__closed(this);
37 this.fireEvent("close", this);
38 },
39 subEvent: function(event) {
40 if($defined(this.subWindow))
41 this.subWindow.fireEvent(event);
42 },
43 setSubWindow: function(window) {
44 this.subWindow = window;
45 },
46 select: function() {
47 this.active = true;
48 this.parentObject.__setActiveWindow(this);
49 if(this.hilighted)
50 this.setHilighted(qwebirc.ui.HILIGHT_NONE);
51
52 this.subEvent("select");
53 this.resetScrollPos();
54 this.lastSelected = new Date();
55 },
56 deselect: function() {
57 this.subEvent("deselect");
58
59 this.setScrollPos();
60 if($defined(this.scrolltimer)) {
61 $clear(this.scrolltimer);
62 this.scrolltimer = null;
63 }
64
65 this.active = false;
66 },
67 resetScrollPos: function() {
68 if(this.scrolleddown) {
69 this.scrollToBottom();
70 } else if($defined(this.scrollpos)) {
71 this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y);
72 }
73 },
74 setScrollPos: function() {
75 if(!this.parentObject.singleWindow) {
76 this.scrolleddown = this.scrolledDown();
77 this.scrollpos = this.lines.getScroll();
78 }
79 },
80 addLine: function(type, line, colour, element) {
81 var hilight = qwebirc.ui.HILIGHT_NONE;
82 var lhilight = false;
83
84 if(type) {
85 hilight = qwebirc.ui.HILIGHT_ACTIVITY;
86
87 if(type.match(/(NOTICE|ACTION|MSG)$/)) {
88 if(this.type == qwebirc.ui.WINDOW_QUERY || this.type == qwebirc.ui.WINDOW_MESSAGES) {
89 if(type.match(/^OUR/) || type.match(/NOTICE$/)) {
90 hilight = qwebirc.ui.HILIGHT_ACTIVITY;
91 } else {
92 hilight = qwebirc.ui.HILIGHT_US;
93 this.parentObject.beep();
94 }
95 }
96 if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) {
97 lhilight = true;
98 hilight = qwebirc.ui.HILIGHT_US;
99 this.parentObject.beep();
100 } else if(hilight != qwebirc.ui.HILIGHT_US) {
101 hilight = qwebirc.ui.HILIGHT_SPEECH;
102 }
103 }
104 }
105
106 if(!this.active && (hilight != qwebirc.ui.HILIGHT_NONE))
107 this.setHilighted(hilight);
108
109 if(type)
110 line = this.parentObject.theme.message(type, line, lhilight);
111
112 qwebirc.ui.Colourise(qwebirc.irc.IRCTimestamp(new Date()) + " " + line, element, this.client.exec, this.parentObject.urlDispatcher.bind(this.parentObject), this);
113 this.scrollAdd(element);
114 },
115 errorMessage: function(message) {
116 this.addLine("", message, "warncolour");
117 },
118 infoMessage: function(message) {
119 this.addLine("", message, "infocolour");
120 },
121 setHilighted: function(state) {
122 if(state == qwebirc.ui.HILIGHT_NONE || state >= this.hilighted)
123 this.hilighted = state;
124 },
125 scrolledDown: function() {
126 if(this.scrolltimer)
127 return true;
128
129 var parent = this.lines;
130
131 var prev = parent.getScroll();
132 var prevbottom = parent.getScrollSize().y;
133 var prevsize = parent.getSize();
134
135 /* fixes an IE bug */
136 if(prevbottom < prevsize.y)
137 prevbottom = prevsize.y;
138
139 return prev.y + prevsize.y == prevbottom;
140 },
141 getScrollParent: function() {
142 var scrollparent = this.lines;
143
144 if($defined(this.scroller))
145 scrollparent = this.scroller;
146 return scrollparent;
147 },
148 scrollToBottom: function() {
149 if(this.type == qwebirc.ui.WINDOW_CUSTOM || this.type == qwebirc.ui.WINDOW_CONNECT)
150 return;
151
152 var parent = this.lines;
153 var scrollparent = this.getScrollParent();
154
155 scrollparent.scrollTo(parent.getScroll().x, parent.getScrollSize().y);
156 },
157 scrollAdd: function(element) {
158 var parent = this.lines;
159
160 /* scroll in bursts, else the browser gets really slow */
161 if($defined(element)) {
162 var sd = this.scrolledDown();
163 parent.appendChild(element);
164 if(sd) {
165 if(this.scrolltimer)
166 $clear(this.scrolltimer);
167 this.scrolltimer = this.scrollAdd.delay(50, this, [null]);
168 }
169 } else {
170 this.scrollToBottom();
171 this.scrolltimer = null;
172 }
173 },
174 updateNickList: function(nicks) {
175 var nickHash = {}, present = {};
176 var added = [];
177 var lnh = this.lastNickHash;
178
179 for(var i=0;i<nicks.length;i++)
180 present[nicks[i]] = 1;
181
182 for(var k in lnh)
183 if(!present[k])
184 this.nickListRemove(k, lnh[k]);
185
186 for(var i=0;i<nicks.length;i++) {
187 var n = nicks[i];
188 var l = lnh[n];
189 if(!l) {
190 l = this.nickListAdd(n, i);
191 if(!l)
192 l = 1;
193 }
194 nickHash[n] = l;
195 }
196
197 this.lastNickHash = nickHash;
198 },
199 nickListAdd: function(position, nick) {
200 },
201 nickListRemove: function(nick, stored) {
202 },
203 historyExec: function(line) {
204 this.commandhistory.addLine(line);
205 this.client.exec(line);
206 }
207 });