]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/qui.js
New favicon courtesy of meeb.
[irc/quakenet/qwebirc.git] / js / ui / qui.js
CommitLineData
e20e5a6b
CP
1qwebirc.ui.QUI = new Class({
2 Extends: qwebirc.ui.NewLoginUI,
3 initialize: function(parentElement, theme) {
4 this.parent(parentElement, qwebirc.ui.QUI.Window, "qui");
5 this.theme = theme;
6 this.parentElement = parentElement;
7 },
8 postInitialize: function() {
9 this.qjsui = new qwebirc.ui.QUI.JSUI("qwebirc-qui", this.parentElement);
10
11 this.qjsui.top.addClass("tabbar");
12
13 this.qjsui.bottom.addClass("input");
14 this.qjsui.right.addClass("nicklist");
15 this.qjsui.topic.addClass("topic");
16 this.qjsui.middle.addClass("lines");
17
18 this.tabs = this.qjsui.top;
19 this.origtopic = this.topic = this.qjsui.topic;
20 this.origlines = this.lines = this.qjsui.middle;
21 this.orignicklist = this.nicklist = this.qjsui.right;
22
23 this.input = this.qjsui.bottom;
24 this.reflow = this.qjsui.reflow.bind(this.qjsui);
25
26 this.createInput();
27 this.reflow();
28 },
29 createInput: function() {
30 var form = new Element("form");
31 this.input.appendChild(form);
32 form.addClass("input");
33
34 var inputbox = new Element("input");
35 form.appendChild(inputbox);
36 this.inputbox = inputbox;
37
38 form.addEvent("submit", function(e) {
39 new Event(e).stop();
40
41 if(inputbox.value == "")
42 return;
43
44 this.getActiveWindow().historyExec(inputbox.value);
45 inputbox.value = "";
46 }.bind(this));
47
48 inputbox.addEvent("keydown", function(e) {
49 var resultfn;
50 var cvalue = inputbox.value;
51
52 if(e.key == "up") {
53 resultfn = this.commandhistory.upLine;
54 } else if(e.key == "down") {
55 resultfn = this.commandhistory.downLine;
56 } else {
57 return;
58 }
59
60 if((cvalue != "") && (this.lastcvalue != cvalue))
61 this.commandhistory.addLine(cvalue, true);
62
63 var result = resultfn.bind(this.commandhistory)();
64
65 new Event(e).stop();
66 if(!result)
67 result = "";
68 this.lastcvalue = result;
69
70 inputbox.value = result;
1d6756bc 71 qwebirc.util.setAtEnd(inputbox);
e20e5a6b
CP
72 }.bind(this));
73 },
74 setLines: function(lines) {
75 this.lines.parentNode.replaceChild(lines, this.lines);
76 this.qjsui.middle = this.lines = lines;
77 },
78 setChannelItems: function(nicklist, topic) {
79 if(!$defined(nicklist)) {
80 nicklist = this.orignicklist;
81 topic = this.origtopic;
82 }
83 this.nicklist.parentNode.replaceChild(nicklist, this.nicklist);
84 this.qjsui.right = this.nicklist = nicklist;
85
86 this.topic.parentNode.replaceChild(topic, this.topic);
87 this.qjsui.topic = this.topic = topic;
88 }
89});
90
91qwebirc.ui.QUI.JSUI = new Class({
b1ee83f3
CP
92 initialize: function(class_, parent, sizer) {
93 this.parent = parent;
94 this.sizer = $defined(sizer)?sizer:parent;
95
24ede2cb
CP
96 this.class_ = class_;
97 this.create();
98
6c19eb8f
CP
99 this.reflowevent = null;
100
b1ee83f3 101 window.addEvent("resize", function() {
6c19eb8f 102 this.reflow(100);
b1ee83f3
CP
103 }.bind(this));
104 },
24ede2cb 105 applyClasses: function(pos, l) {
6c19eb8f 106 l.addClass("dynamicpanel");
24ede2cb 107 l.addClass(this.class_);
6c19eb8f 108
24ede2cb
CP
109 if(pos == "middle") {
110 l.addClass("leftboundpanel");
111 } else if(pos == "top") {
112 l.addClass("topboundpanel");
113 l.addClass("widepanel");
114 } else if(pos == "topic") {
115 l.addClass("widepanel");
116 } else if(pos == "right") {
117 l.addClass("rightboundpanel");
118 } else if(pos == "bottom") {
119 l.addClass("bottomboundpanel");
120 l.addClass("widepanel");
121 }
122 },
123 create: function() {
124 var XE = function(pos) {
125 var element = new Element("div");
126 this.applyClasses(pos, element);
b1ee83f3 127
24ede2cb
CP
128 this.parent.appendChild(element);
129 return element;
b1ee83f3
CP
130 }.bind(this);
131
24ede2cb
CP
132 this.top = XE("top");
133 this.topic = XE("topic");
134 this.middle = XE("middle");
135 this.right = XE("right");
136 this.bottom = XE("bottom");
b1ee83f3 137 },
6c19eb8f
CP
138 reflow: function(delay) {
139 if(!delay)
140 delay = 1;
141
142 if(this.reflowevent)
143 $clear(this.reflowevent);
144 this.__reflow();
145 this.reflowevent = this.__reflow.delay(delay, this);
146 },
147 __reflow: function() {
b1ee83f3
CP
148 var bottom = this.bottom;
149 var middle = this.middle;
150 var right = this.right;
151 var topic = this.topic;
152 var top = this.top;
153
154 var topicsize = topic.getSize();
155 var topsize = top.getSize();
156 var rightsize = right.getSize();
157 var bottomsize = bottom.getSize();
158 var docsize = this.sizer.getSize();
159
160 var mheight = (docsize.y - topsize.y - bottomsize.y - topicsize.y);
161 var mwidth = (docsize.x - rightsize.x);
162
163 topic.setStyle("top", topsize.y + "px");
164
165 middle.setStyle("top", (topsize.y + topicsize.y) + "px");
166 if(mheight > 0) {
167 middle.setStyle("height", mheight + "px");
168 right.setStyle("height", mheight + "px");
169 }
170
6c19eb8f 171 if(mwidth > 0)
b1ee83f3 172 middle.setStyle("width", mwidth + "px");
b1ee83f3
CP
173 right.setStyle("top", (topsize.y + topicsize.y) + "px");
174 right.setStyle("left", mwidth + "px");
175
176 bottom.setStyle("top", (docsize.y - bottomsize.y) + "px");
177 },
178 showChannel: function(state) {
179 var display = "none";
180 if(state)
181 display = "block";
182
183 this.right.setStyle("display", display);
184 this.topic.setStyle("display", display);
6c19eb8f
CP
185 },
186 showInput: function(state) {
187 this.bottom.setStyle("display", state?"block":"none");
b1ee83f3
CP
188 }
189});
35155ba7 190
e20e5a6b
CP
191qwebirc.ui.QUI.Window = new Class({
192 Extends: qwebirc.ui.Window,
f4ae92cc
CP
193
194 initialize: function(parentObject, client, type, name) {
195 this.parent(parentObject, client, type, name);
be0bd774 196
66de775f 197 this.tab = new Element("a", {"href": "#"});
f4ae92cc 198 this.tab.addClass("tab");
fd60516d
CP
199 this.tab.addEvent("focus", function() { this.blur() }.bind(this.tab));;
200
35155ba7 201 parentObject.tabs.appendChild(this.tab);
f4ae92cc
CP
202
203 this.tab.appendText(name);
66de775f
CP
204 this.tab.addEvent("click", function(e) {
205 new Event(e).stop();
f4ae92cc
CP
206 parentObject.selectWindow(this);
207 }.bind(this));
f4ae92cc 208
e20e5a6b
CP
209 if(type != qwebirc.ui.WINDOW_STATUS && type != qwebirc.ui.WINDOW_CONNECT) {
210 var tabclose = new Element("span");
211 tabclose.set("text", "X");
f4ae92cc
CP
212 tabclose.addClass("tabclose");
213 tabclose.addEvent("click", function(e) {
214 new Event(e).stop();
215
e20e5a6b 216 if(type == qwebirc.ui.WINDOW_CHANNEL)
f4ae92cc
CP
217 this.client.exec("/PART " + name);
218
219 this.close();
220 }.bind(this));
52090a1f 221
f4ae92cc
CP
222 this.tab.appendChild(tabclose);
223 }
be0bd774 224
be0bd774 225 this.lines = new Element("div");
6c19eb8f 226 this.parentObject.qjsui.applyClasses("middle", this.lines);
be0bd774 227 this.lines.addClass("lines");
6c19eb8f 228
b1ee83f3
CP
229 this.lines.addEvent("scroll", function() {
230 this.scrolleddown = this.scrolledDown();
be0bd774 231 }.bind(this));
be0bd774 232
e20e5a6b 233 if(type == qwebirc.ui.WINDOW_CHANNEL) {
be0bd774
CP
234 this.topic = new Element("div");
235 this.topic.addClass("topic");
b1ee83f3 236 this.topic.addClass("tab-invisible");
be0bd774 237 this.topic.set("html", " ");
6c19eb8f 238 this.parentObject.qjsui.applyClasses("topic", this.topic);
be0bd774 239
52090a1f 240 this.prevNick = null;
66de775f
CP
241 this.nicklist = new Element("div");
242 this.nicklist.addClass("nicklist");
b1ee83f3 243 this.nicklist.addClass("tab-invisible");
cffd43cf 244 this.nicklist.addEvent("click", this.removePrevMenu.bind(this));
6c19eb8f 245 this.parentObject.qjsui.applyClasses("nicklist", this.nicklist);
be0bd774 246 }
b1ee83f3 247
e20e5a6b 248 if(type == qwebirc.ui.WINDOW_CHANNEL) {
359b7edd
CP
249 this.updateTopic("");
250 } else {
251 this.reflow();
252 }
b1ee83f3
CP
253 },
254 reflow: function() {
255 this.parentObject.reflow();
35155ba7
CP
256 },
257 onResize: function() {
258 if(this.scrolleddown)
259 this.scrollToBottom();
359b7edd 260 },
cffd43cf 261 createMenu: function(nick, parent) {
d2512acf 262 var e = new Element("div");
cffd43cf
CP
263 parent.appendChild(e);
264 e.addClass("menu");
265
266 qwebirc.ui.MENU_ITEMS.forEach(function(x) {
d2512acf 267 var e2 = new Element("a");
cffd43cf
CP
268 e.appendChild(e2);
269
270 e2.href = "#";
271 e2.set("text", "- " + x[0]);
272
273 e2.addEvent("focus", function() { this.blur() }.bind(e2));
274 e2.addEvent("click", function(ev) { new Event(ev.stop()); this.menuClick(x[1]); }.bind(this));
275 }.bind(this));
276 return e;
277 },
278 menuClick: function(fn) {
279 /*
280 this.prevNick.removeChild(this.prevNick.menu);
281 this.prevNick.menu = null;
282 */
283 fn.bind(this)(this.prevNick.realNick);
284 this.removePrevMenu();
285 },
d8272bcb
CP
286 moveMenuClass: function() {
287 if(!this.prevNick)
288 return;
289 if(this.nicklist.firstChild == this.prevNick) {
290 this.prevNick.removeClass("selected-middle");
291 } else {
292 this.prevNick.addClass("selected-middle");
293 }
294 },
cffd43cf
CP
295 removePrevMenu: function() {
296 if(!this.prevNick)
297 return;
298
299 this.prevNick.removeClass("selected");
d8272bcb 300 this.prevNick.removeClass("selected-middle");
cffd43cf
CP
301 if(this.prevNick.menu)
302 this.prevNick.removeChild(this.prevNick.menu);
303 this.prevNick = null;
304 },
52090a1f
CP
305 nickListAdd: function(nick, position) {
306 var e = new Element("a");
307 qwebirc.ui.insertAt(position, this.nicklist, e);
f4ae92cc 308
52090a1f
CP
309 e.href = "#";
310 e.appendChild(document.createTextNode(nick));
311
312 e.realNick = this.client.stripPrefix(nick);
313
314 e.addEvent("click", function(x) {
aab6d06a
CP
315 if(this.prevNick == e) {
316 this.removePrevMenu();
317 return;
318 }
319
cffd43cf 320 this.removePrevMenu();
52090a1f
CP
321 this.prevNick = e;
322 e.addClass("selected");
d8272bcb 323 this.moveMenuClass();
cffd43cf 324 e.menu = this.createMenu(x.realNick, e);
52090a1f
CP
325 new Event(x).stop();
326 }.bind(this));
327 e.addEvent("dblclick", function(x) {
328 new Event(x).stop();
329 this.client.exec("/QUERY " + e.realNick);
330 }.bind(this));
331
fd60516d 332 e.addEvent("focus", function() { this.blur() }.bind(e));
d8272bcb 333 this.moveMenuClass();
52090a1f
CP
334 return e;
335 },
336 nickListRemove: function(nick, stored) {
337 this.nicklist.removeChild(stored);
d8272bcb 338 this.moveMenuClass();
f4ae92cc
CP
339 },
340 updateTopic: function(topic) {
f4ae92cc
CP
341 var t = this.topic;
342
343 while(t.firstChild)
344 t.removeChild(t.firstChild);
345
66de775f 346 if(topic) {
1f06a70a 347 this.parent(topic, t);
66de775f 348 } else {
359b7edd
CP
349 var e = new Element("div");
350 e.set("text", "(no topic set)");
66de775f 351 e.addClass("emptytopic");
359b7edd 352 t.appendChild(e);
66de775f 353 }
359b7edd 354 this.reflow();
f4ae92cc
CP
355 },
356 select: function() {
e20e5a6b 357 var inputVisible = this.type != qwebirc.ui.WINDOW_CONNECT && this.type != qwebirc.ui.WINDOW_CUSTOM;
6c19eb8f 358
f4ae92cc 359 this.tab.removeClass("tab-unselected");
f4ae92cc 360 this.tab.addClass("tab-selected");
359b7edd 361
6c19eb8f
CP
362 this.parentObject.setLines(this.lines);
363 this.parentObject.setChannelItems(this.nicklist, this.topic);
364 this.parentObject.qjsui.showInput(inputVisible);
365 this.parentObject.qjsui.showChannel($defined(this.nicklist));
366
367 this.reflow();
24ede2cb 368
7c633700 369 this.parent();
25be5960 370
6c19eb8f
CP
371 if(inputVisible)
372 this.parentObject.inputbox.focus();
f4ae92cc
CP
373 },
374 deselect: function() {
375 this.parent();
376
f4ae92cc
CP
377 this.tab.removeClass("tab-selected");
378 this.tab.addClass("tab-unselected");
379 },
380 close: function() {
381 this.parent();
382
f4ae92cc
CP
383 this.parentObject.tabs.removeChild(this.tab);
384 },
385 addLine: function(type, line, colour) {
f4ae92cc
CP
386 var e = new Element("div");
387
388 if(colour) {
389 e.setStyles({"background": colour});
390 } else if(this.lastcolour) {
391 e.addClass("linestyle1");
392 } else {
393 e.addClass("linestyle2");
394 }
f4ae92cc 395 this.lastcolour = !this.lastcolour;
35155ba7 396
be0bd774
CP
397 this.parent(type, line, colour, e);
398 },
399 setHilighted: function(state) {
96f28062
CP
400 laststate = this.hilighted;
401
be0bd774 402 this.parent(state);
96f28062
CP
403
404 if(state == laststate)
405 return;
406
407 this.tab.removeClass("tab-hilight-activity");
408 this.tab.removeClass("tab-hilight-us");
409 this.tab.removeClass("tab-hilight-speech");
f4ae92cc 410
96f28062
CP
411 switch(this.hilighted) {
412 case qwebirc.ui.HILIGHT_US:
413 this.tab.addClass("tab-hilight-us");
414 break;
415 case qwebirc.ui.HILIGHT_SPEECH:
416 this.tab.addClass("tab-hilight-speech");
417 break;
418 case qwebirc.ui.HILIGHT_ACTIVITY:
419 this.tab.addClass("tab-hilight-activity");
420 break;
be0bd774 421 }
f4ae92cc
CP
422 }
423});