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