]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/frontends/qui.js
another silly QHash bug
[irc/quakenet/qwebirc.git] / js / ui / frontends / qui.js
CommitLineData
e20e5a6b 1qwebirc.ui.QUI = new Class({
144ee52f 2 Extends: qwebirc.ui.RootUI,
2cad083e
CP
3 initialize: function(parentElement, theme, options) {
4 this.parent(parentElement, qwebirc.ui.QUI.Window, "qui", options);
e20e5a6b
CP
5 this.theme = theme;
6 this.parentElement = parentElement;
4dd199c3 7 this.setModifiableStylesheet("qui");
e20e5a6b
CP
8 },
9 postInitialize: function() {
10 this.qjsui = new qwebirc.ui.QUI.JSUI("qwebirc-qui", this.parentElement);
bfbe72f9
CP
11 this.qjsui.addEvent("reflow", function() {
12 var w = this.getActiveWindow();
13 if($defined(w))
14 w.onResize();
15 }.bind(this));
941e1642 16 this.qjsui.top.addClass("outertabbar");
a4a71818
CP
17 this.qjsui.left.addClass("outertabbar");
18
19 this.qjsui.top.addClass("outertabbar_top");
20 this.qjsui.left.addClass("outertabbar_left");
21
e20e5a6b
CP
22 this.qjsui.bottom.addClass("input");
23 this.qjsui.right.addClass("nicklist");
24 this.qjsui.topic.addClass("topic");
25 this.qjsui.middle.addClass("lines");
26
a4a71818
CP
27 this.outerTabs = new Element("div");
28 this.sideTabs = null;
0989d983 29
941e1642
CP
30 this.tabs = new Element("div");
31 this.tabs.addClass("tabbar");
9da8639a
CP
32
33 this.__createDropdownMenu();
a4a71818 34
941e1642 35 this.outerTabs.appendChild(this.tabs);
e20e5a6b 36 this.origtopic = this.topic = this.qjsui.topic;
a4a71818 37 this.lines = this.qjsui.middle;
e20e5a6b
CP
38 this.orignicklist = this.nicklist = this.qjsui.right;
39
40 this.input = this.qjsui.bottom;
41 this.reflow = this.qjsui.reflow.bind(this.qjsui);
42
ff4befd8 43 this.tabs.addEvent("mousewheel", function(x) {
a4a71818
CP
44 if(this.sideTabs)
45 return;
46
ff4befd8 47 var event = new Event(x);
a4a71818 48
ff4befd8
CP
49 /* up */
50 if(event.wheel > 0) {
51 this.nextWindow();
52 } else if(event.wheel < 0) {
53 /* down */
b35116e2 54 this.prevWindow();
ff4befd8
CP
55 }
56 event.stop();
57 }.bind(this));
58
e20e5a6b
CP
59 this.createInput();
60 this.reflow();
0a55be30 61 this.reflow.delay(100); /* Konqueror fix */
a4a71818
CP
62 this.setSideTabs(this.uiOptions.SIDE_TABS);
63
64 },
65 newWindow: function(client, type, name) {
66 var w = this.parent(client, type, name);
67 w.setSideTabs(this.sideTabs);
68 return w;
e20e5a6b 69 },
0989d983 70 __createDropdownMenu: function() {
e9837dce 71 var dropdownMenu = new Element("span");
43cb8910 72 dropdownMenu.addClass("dropdownmenu");
0989d983
CP
73
74 dropdownMenu.hide = function() {
43cb8910
CP
75 dropdownMenu.setStyle("display", "none");
76 dropdownMenu.visible = false;
e9837dce 77 document.removeEvent("mousedown", hideEvent);
43cb8910 78 }.bind(this);
e9837dce 79 var hideEvent = function() { dropdownMenu.hide(); };
0989d983
CP
80
81 dropdownMenu.hide();
43cb8910
CP
82 this.parentElement.appendChild(dropdownMenu);
83
84 this.UICommands.forEach(function(x) {
85 var text = x[0];
86 var fn = this[x[1] + "Window"].bind(this);
87 var e = new Element("a");
0989d983 88 e.addEvent("mousedown", function(e) { new Event(e).stop(); });
43cb8910
CP
89 e.addEvent("click", function() {
90 dropdownMenu.hide();
91 fn();
92 });
93 e.set("text", text);
94 dropdownMenu.appendChild(e);
95 }.bind(this));
96
941e1642 97 var dropdown = new Element("div");
43cb8910 98 dropdown.addClass("dropdown-tab");
fbe5af77 99 dropdown.appendChild(new Element("img", {src: qwebirc.global.staticBaseURL + "images/icon.png", title: "menu", alt: "menu"}));
391f51ff
CP
100 dropdown.setStyle("opacity", 1);
101
941e1642 102 this.outerTabs.appendChild(dropdown);
9da8639a 103 dropdownMenu.show = function(x) {
43cb8910 104 new Event(x).stop();
321abaf8 105
43cb8910
CP
106 if(dropdownMenu.visible) {
107 dropdownMenu.hide();
108 return;
109 }
a4a71818
CP
110 var parentSize = this.outerTabs.parentNode.getSize().y;
111
112 dropdownMenu.setStyle("left", parentSize.x);
385143a6 113 dropdownMenu.setStyle("top", top-1); /* -1 == top border */
43cb8910
CP
114 dropdownMenu.setStyle("display", "inline-block");
115 dropdownMenu.visible = true;
e9837dce
CP
116
117 document.addEvent("mousedown", hideEvent);
43cb8910 118 }.bind(this);
e9837dce 119 dropdown.addEvent("mousedown", function(e) { new Event(e).stop(); });
43cb8910 120 dropdown.addEvent("click", dropdownMenu.show);
0989d983 121 },
e20e5a6b
CP
122 createInput: function() {
123 var form = new Element("form");
124 this.input.appendChild(form);
c1416a8d 125
e20e5a6b
CP
126 form.addClass("input");
127
128 var inputbox = new Element("input");
fc38a626 129 this.addEvent("signedOn", function() {
1761242b 130 inputbox.placeholder = "chat here! you can also use commands, like /JOIN or /HELP";
63494576
CP
131 var d = function() { inputbox.addClass("input-flash"); }.delay(250);
132 var d = function() { inputbox.removeClass("input-flash"); }.delay(500);
133 var d = function() { inputbox.addClass("input-flash"); }.delay(750);
134 var d = function() { inputbox.removeClass("input-flash"); }.delay(1000);
135 var d = function() { inputbox.addClass("input-flash"); }.delay(1250);
136 var d = function() { inputbox.removeClass("input-flash"); }.delay(1750);
fc38a626 137 });
e20e5a6b
CP
138 form.appendChild(inputbox);
139 this.inputbox = inputbox;
7c82e345 140 this.inputbox.maxLength = 470;
c1416a8d
CP
141
142 var sendInput = function() {
e20e5a6b
CP
143 if(inputbox.value == "")
144 return;
145
3184781b 146 this.resetTabComplete();
e20e5a6b
CP
147 this.getActiveWindow().historyExec(inputbox.value);
148 inputbox.value = "";
fc38a626 149 inputbox.placeholder = "";
c1416a8d
CP
150 }.bind(this);
151
152 if(!qwebirc.util.deviceHasKeyboard()) {
153 inputbox.addClass("mobile-input");
154 var inputButton = new Element("input", {type: "button"});
155 inputButton.addClass("mobile-button");
156 inputButton.addEvent("click", function() {
157 sendInput();
158 inputbox.focus();
159 });
160 inputButton.value = ">";
161 this.input.appendChild(inputButton);
162 var reflowButton = function() {
163 var containerSize = this.input.getSize();
164 var buttonSize = inputButton.getSize();
165
166 var buttonLeft = containerSize.x - buttonSize.x - 5; /* lovely 5 */
167
168 inputButton.setStyle("left", buttonLeft);
169 inputbox.setStyle("width", buttonLeft - 5);
170 inputButton.setStyle("height", containerSize.y);
171 }.bind(this);
172 this.qjsui.addEvent("reflow", reflowButton);
173 } else {
174 inputbox.addClass("keyboard-input");
175 }
176
177 form.addEvent("submit", function(e) {
178 new Event(e).stop();
179 sendInput();
180 });
e20e5a6b 181
3184781b
CP
182 inputbox.addEvent("focus", this.resetTabComplete.bind(this));
183 inputbox.addEvent("mousedown", this.resetTabComplete.bind(this));
184
e20e5a6b
CP
185 inputbox.addEvent("keydown", function(e) {
186 var resultfn;
187 var cvalue = inputbox.value;
3184781b 188
e20e5a6b
CP
189 if(e.key == "up") {
190 resultfn = this.commandhistory.upLine;
191 } else if(e.key == "down") {
192 resultfn = this.commandhistory.downLine;
325d6a9f 193 } else if(e.key == "tab" && !e.altKey && !e.ctrlKey && !e.shiftKey) {
3184781b
CP
194 new Event(e).stop();
195 this.tabComplete(inputbox);
196 return;
e20e5a6b 197 } else {
3184781b
CP
198 /* ideally alt and other keys wouldn't break this */
199 this.resetTabComplete();
e20e5a6b
CP
200 return;
201 }
202
3184781b 203 this.resetTabComplete();
e20e5a6b
CP
204 if((cvalue != "") && (this.lastcvalue != cvalue))
205 this.commandhistory.addLine(cvalue, true);
206
207 var result = resultfn.bind(this.commandhistory)();
208
209 new Event(e).stop();
210 if(!result)
211 result = "";
212 this.lastcvalue = result;
213
214 inputbox.value = result;
1d6756bc 215 qwebirc.util.setAtEnd(inputbox);
e20e5a6b
CP
216 }.bind(this));
217 },
218 setLines: function(lines) {
219 this.lines.parentNode.replaceChild(lines, this.lines);
220 this.qjsui.middle = this.lines = lines;
221 },
222 setChannelItems: function(nicklist, topic) {
223 if(!$defined(nicklist)) {
224 nicklist = this.orignicklist;
225 topic = this.origtopic;
226 }
227 this.nicklist.parentNode.replaceChild(nicklist, this.nicklist);
228 this.qjsui.right = this.nicklist = nicklist;
229
230 this.topic.parentNode.replaceChild(topic, this.topic);
231 this.qjsui.topic = this.topic = topic;
a4a71818
CP
232 },
233 setSideTabs: function(value) {
234 if(value === this.sideTabs)
235 return;
236
237 if(this.sideTabs === true) {
238 this.qjsui.left.removeChild(this.outerTabs);
239 } else if(this.sideTabs === false) {
240 this.qjsui.top.removeChild(this.outerTabs);
241 }
242 if(value) {
243 this.qjsui.left.appendChild(this.outerTabs);
244 this.qjsui.top.style.display = "none";
245 this.qjsui.left.style.display = "";
246 } else {
247 this.qjsui.top.appendChild(this.outerTabs);
248 this.qjsui.top.style.display = "";
249 this.qjsui.left.style.display = "none";
250 }
251 this.sideTabs = value;
252 this.windows.each(function(k, v) {
253 v.each(function(k, v2) {
254 v2.setSideTabs(value);
255 });
256 });
e20e5a6b
CP
257 }
258});
259
260qwebirc.ui.QUI.JSUI = new Class({
bfbe72f9 261 Implements: [Events],
b1ee83f3
CP
262 initialize: function(class_, parent, sizer) {
263 this.parent = parent;
264 this.sizer = $defined(sizer)?sizer:parent;
a4a71818 265
24ede2cb
CP
266 this.class_ = class_;
267 this.create();
268
6c19eb8f
CP
269 this.reflowevent = null;
270
b1ee83f3 271 window.addEvent("resize", function() {
6c19eb8f 272 this.reflow(100);
b1ee83f3
CP
273 }.bind(this));
274 },
24ede2cb 275 applyClasses: function(pos, l) {
6c19eb8f 276 l.addClass("dynamicpanel");
24ede2cb 277 l.addClass(this.class_);
a4a71818 278 l.addClass(pos + "boundpanel");
24ede2cb
CP
279 },
280 create: function() {
281 var XE = function(pos) {
282 var element = new Element("div");
283 this.applyClasses(pos, element);
b1ee83f3 284
24ede2cb
CP
285 this.parent.appendChild(element);
286 return element;
b1ee83f3
CP
287 }.bind(this);
288
24ede2cb 289 this.top = XE("top");
a4a71818 290 this.left = XE("left");
24ede2cb
CP
291 this.topic = XE("topic");
292 this.middle = XE("middle");
293 this.right = XE("right");
294 this.bottom = XE("bottom");
b1ee83f3 295 },
6c19eb8f
CP
296 reflow: function(delay) {
297 if(!delay)
298 delay = 1;
299
300 if(this.reflowevent)
301 $clear(this.reflowevent);
302 this.__reflow();
303 this.reflowevent = this.__reflow.delay(delay, this);
304 },
305 __reflow: function() {
b1ee83f3
CP
306 var bottom = this.bottom;
307 var middle = this.middle;
308 var right = this.right;
309 var topic = this.topic;
310 var top = this.top;
a4a71818
CP
311 var left = this.left;
312
313 /* |----------------------------------------------|
314 * | top |
315 * |----------------------------------------------|
316 * | left | topic | right |
317 * | |-------------------------------| |
318 * | | middle | |
319 * | | | |
320 * | | | |
321 * | |---------------------------------------|
322 * | | bottom |
323 * |----------------------------------------------|
324 */
325
b1ee83f3
CP
326 var topicsize = topic.getSize();
327 var topsize = top.getSize();
328 var rightsize = right.getSize();
329 var bottomsize = bottom.getSize();
a4a71818 330 var leftsize = left.getSize();
b1ee83f3
CP
331 var docsize = this.sizer.getSize();
332
333 var mheight = (docsize.y - topsize.y - bottomsize.y - topicsize.y);
6e18a495 334 var mwidth = (docsize.x - rightsize.x - leftsize.x);
b1ee83f3 335
a4a71818 336 left.setStyle("top", topsize.y);
4b9f894d 337 topic.setStyle("top", topsize.y);
a4a71818 338 topic.setStyle("left", leftsize.x);
b1ee83f3 339
4b9f894d 340 middle.setStyle("top", (topsize.y + topicsize.y));
a4a71818 341 middle.setStyle("left", leftsize.x);
b1ee83f3 342 if(mheight > 0) {
4b9f894d
CP
343 middle.setStyle("height", mheight);
344 right.setStyle("height", mheight);
b1ee83f3
CP
345 }
346
6c19eb8f 347 if(mwidth > 0)
4b9f894d
CP
348 middle.setStyle("width", mwidth);
349 right.setStyle("top", (topsize.y + topicsize.y));
a4a71818
CP
350
351 bottom.setStyle("left", leftsize.x);
bfbe72f9 352 this.fireEvent("reflow");
b1ee83f3 353 },
5f464ed5 354 showChannel: function(state, nicklistVisible) {
b1ee83f3
CP
355 var display = "none";
356 if(state)
357 display = "block";
358
5f464ed5 359 this.right.setStyle("display", nicklistVisible ? display : "none");
b1ee83f3 360 this.topic.setStyle("display", display);
6c19eb8f
CP
361 },
362 showInput: function(state) {
941e1642 363 this.bottom.isVisible = state;
6c19eb8f 364 this.bottom.setStyle("display", state?"block":"none");
b1ee83f3
CP
365 }
366});
35155ba7 367
e20e5a6b
CP
368qwebirc.ui.QUI.Window = new Class({
369 Extends: qwebirc.ui.Window,
f4ae92cc 370
f74802c5
CP
371 initialize: function(parentObject, client, type, name, identifier) {
372 this.parent(parentObject, client, type, name, identifier);
be0bd774 373
66de775f 374 this.tab = new Element("a", {"href": "#"});
f4ae92cc 375 this.tab.addClass("tab");
fd60516d 376 this.tab.addEvent("focus", function() { this.blur() }.bind(this.tab));;
ff1c78b3
CP
377
378 this.spaceNode = document.createTextNode(" ");
35155ba7 379 parentObject.tabs.appendChild(this.tab);
ff1c78b3 380 parentObject.tabs.appendChild(this.spaceNode);
a4a71818 381
e20e5a6b
CP
382 if(type != qwebirc.ui.WINDOW_STATUS && type != qwebirc.ui.WINDOW_CONNECT) {
383 var tabclose = new Element("span");
a4a71818 384 this.tabclose = tabclose;
e20e5a6b 385 tabclose.set("text", "X");
f4ae92cc 386 tabclose.addClass("tabclose");
f84bf379 387 var close = function(e) {
f4ae92cc 388 new Event(e).stop();
a4a71818 389
f84bf379
CP
390 if(this.closed)
391 return;
a4a71818 392
e20e5a6b 393 if(type == qwebirc.ui.WINDOW_CHANNEL)
f4ae92cc
CP
394 this.client.exec("/PART " + name);
395
396 this.close();
a4a71818 397
941e1642 398 //parentObject.inputbox.focus();
f84bf379 399 }.bind(this);
a4a71818 400
f84bf379
CP
401 tabclose.addEvent("click", close);
402 this.tab.addEvent("mouseup", function(e) {
b46f79e6 403 var button = 1;
a4a71818 404
b46f79e6
CP
405 if(Browser.Engine.trident)
406 button = 4;
407
408 if(e.event.button == button)
f84bf379 409 close(e);
f4ae92cc 410 }.bind(this));
a4a71818 411
f4ae92cc 412 this.tab.appendChild(tabclose);
a4a71818
CP
413 } else {
414 this.tabclose = null;
f4ae92cc 415 }
be0bd774 416
a4a71818
CP
417 this.tab.appendText(name);
418 this.tab.addEvent("click", function(e) {
419 new Event(e).stop();
420
421 if(this.closed)
422 return;
423
424 parentObject.selectWindow(this);
425 }.bind(this));
426
427
be0bd774 428 this.lines = new Element("div");
6c19eb8f 429 this.parentObject.qjsui.applyClasses("middle", this.lines);
be0bd774 430 this.lines.addClass("lines");
e82478eb
CP
431 if(type != qwebirc.ui.WINDOW_CUSTOM && type != qwebirc.ui.WINDOW_CONNECT)
432 this.lines.addClass("ircwindow");
6c19eb8f 433
b1ee83f3
CP
434 this.lines.addEvent("scroll", function() {
435 this.scrolleddown = this.scrolledDown();
ff6a32cc 436 this.scrollpos = this.getScrollParent().getScroll();
be0bd774 437 }.bind(this));
be0bd774 438
e20e5a6b 439 if(type == qwebirc.ui.WINDOW_CHANNEL) {
be0bd774 440 this.topic = new Element("div");
a4a71818 441 this.parentObject.qjsui.applyClasses("topic", this.topic);
be0bd774 442 this.topic.addClass("topic");
b1ee83f3 443 this.topic.addClass("tab-invisible");
be0bd774 444 this.topic.set("html", "&nbsp;");
8eb4377c 445 this.topic.addEvent("dblclick", this.editTopic.bind(this));
6c19eb8f 446 this.parentObject.qjsui.applyClasses("topic", this.topic);
be0bd774 447
52090a1f 448 this.prevNick = null;
66de775f
CP
449 this.nicklist = new Element("div");
450 this.nicklist.addClass("nicklist");
b1ee83f3 451 this.nicklist.addClass("tab-invisible");
cffd43cf 452 this.nicklist.addEvent("click", this.removePrevMenu.bind(this));
a4a71818 453 this.parentObject.qjsui.applyClasses("right", this.nicklist);
be0bd774 454 }
b1ee83f3 455
ff1c78b3 456 if(type == qwebirc.ui.WINDOW_CHANNEL)
359b7edd 457 this.updateTopic("");
ff1c78b3 458
f121b688 459 this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS;
a4a71818 460 this.reflow();
b1ee83f3 461 },
5aa173fb
CP
462 rename: function(name) {
463 this.tab.replaceChild(document.createTextNode(name), this.tab.firstChild);
464 },
eaf3ed38
CP
465 editTopic: function() {
466 if(!this.client.nickOnChanHasPrefix(this.client.nickname, this.name, "@")) {
467/* var cmodes = this.client.getChannelModes(channel);
468 if(cmodes.indexOf("t")) {*/
95d00e97 469 alert("Sorry, you need to be a channel operator to change the topic!");
eaf3ed38
CP
470 return;
471 /*}*/
472 }
473 var newTopic = prompt("Change topic of " + this.name + " to:", this.topic.topicText);
474 if(newTopic === null)
475 return;
476
477 this.client.exec("/TOPIC " + newTopic);
478 },
b1ee83f3
CP
479 reflow: function() {
480 this.parentObject.reflow();
35155ba7
CP
481 },
482 onResize: function() {
ff6a32cc
CP
483 if(this.scrolleddown) {
484 if(Browser.Engine.trident) {
485 this.scrollToBottom.delay(5, this);
486 } else {
487 this.scrollToBottom();
488 }
489 } else if($defined(this.scrollpos)) {
490 if(Browser.Engine.trident) {
491 this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y);
492 } else {
493 this.getScrollParent().scrollTo.delay(5, this, [this.scrollpos.x, this.scrollpos.y]);
494 }
495 }
359b7edd 496 },
cffd43cf 497 createMenu: function(nick, parent) {
d2512acf 498 var e = new Element("div");
cffd43cf
CP
499 parent.appendChild(e);
500 e.addClass("menu");
501
27add99a 502 var nickArray = [nick];
cffd43cf 503 qwebirc.ui.MENU_ITEMS.forEach(function(x) {
27add99a
CP
504 if(!x.predicate || x.predicate !== true && !x.predicate.apply(this, nickArray))
505 return;
506
507 var e2 = new Element("a");
508 e.appendChild(e2);
7555d601 509
27add99a
CP
510 e2.href = "#";
511 e2.set("text", "- " + x.text);
7555d601 512
27add99a
CP
513 e2.addEvent("focus", function() { this.blur() }.bind(e2));
514 e2.addEvent("click", function(ev) { new Event(ev.stop()); this.menuClick(x.fn); }.bind(this));
cffd43cf
CP
515 }.bind(this));
516 return e;
517 },
518 menuClick: function(fn) {
519 /*
520 this.prevNick.removeChild(this.prevNick.menu);
521 this.prevNick.menu = null;
522 */
523 fn.bind(this)(this.prevNick.realNick);
524 this.removePrevMenu();
525 },
d8272bcb
CP
526 moveMenuClass: function() {
527 if(!this.prevNick)
528 return;
529 if(this.nicklist.firstChild == this.prevNick) {
530 this.prevNick.removeClass("selected-middle");
531 } else {
532 this.prevNick.addClass("selected-middle");
533 }
534 },
cffd43cf
CP
535 removePrevMenu: function() {
536 if(!this.prevNick)
537 return;
538
539 this.prevNick.removeClass("selected");
d8272bcb 540 this.prevNick.removeClass("selected-middle");
cffd43cf
CP
541 if(this.prevNick.menu)
542 this.prevNick.removeChild(this.prevNick.menu);
543 this.prevNick = null;
544 },
52090a1f 545 nickListAdd: function(nick, position) {
f121b688
CP
546 var realNick = this.client.stripPrefix(nick);
547
52090a1f
CP
548 var e = new Element("a");
549 qwebirc.ui.insertAt(position, this.nicklist, e);
f4ae92cc 550
52090a1f 551 e.href = "#";
f121b688
CP
552 var span = new Element("span");
553 if(this.parentObject.uiOptions.NICK_COLOURS) {
554 var colour = realNick.toHSBColour(this.client);
555 if($defined(colour))
556 span.setStyle("color", colour.rgbToHex());
557 }
558 span.set("text", nick);
559 e.appendChild(span);
52090a1f 560
f121b688 561 e.realNick = realNick;
52090a1f
CP
562
563 e.addEvent("click", function(x) {
aab6d06a
CP
564 if(this.prevNick == e) {
565 this.removePrevMenu();
566 return;
567 }
568
cffd43cf 569 this.removePrevMenu();
52090a1f
CP
570 this.prevNick = e;
571 e.addClass("selected");
d8272bcb 572 this.moveMenuClass();
27add99a 573 e.menu = this.createMenu(e.realNick, e);
52090a1f
CP
574 new Event(x).stop();
575 }.bind(this));
52090a1f 576
fd60516d 577 e.addEvent("focus", function() { this.blur() }.bind(e));
d8272bcb 578 this.moveMenuClass();
52090a1f
CP
579 return e;
580 },
581 nickListRemove: function(nick, stored) {
582 this.nicklist.removeChild(stored);
d8272bcb 583 this.moveMenuClass();
f4ae92cc
CP
584 },
585 updateTopic: function(topic) {
f4ae92cc
CP
586 var t = this.topic;
587
588 while(t.firstChild)
589 t.removeChild(t.firstChild);
590
66de775f 591 if(topic) {
eaf3ed38 592 t.topicText = topic;
1f06a70a 593 this.parent(topic, t);
66de775f 594 } else {
eaf3ed38 595 t.topicText = topic;
359b7edd
CP
596 var e = new Element("div");
597 e.set("text", "(no topic set)");
66de775f 598 e.addClass("emptytopic");
359b7edd 599 t.appendChild(e);
66de775f 600 }
359b7edd 601 this.reflow();
f4ae92cc
CP
602 },
603 select: function() {
e20e5a6b 604 var inputVisible = this.type != qwebirc.ui.WINDOW_CONNECT && this.type != qwebirc.ui.WINDOW_CUSTOM;
6c19eb8f 605
f4ae92cc 606 this.tab.removeClass("tab-unselected");
f4ae92cc 607 this.tab.addClass("tab-selected");
359b7edd 608
6c19eb8f
CP
609 this.parentObject.setLines(this.lines);
610 this.parentObject.setChannelItems(this.nicklist, this.topic);
611 this.parentObject.qjsui.showInput(inputVisible);
5f464ed5 612 this.parentObject.qjsui.showChannel($defined(this.nicklist), this.parentObject.uiOptions.SHOW_NICKLIST);
6c19eb8f
CP
613
614 this.reflow();
24ede2cb 615
7c633700 616 this.parent();
25be5960 617
6c19eb8f
CP
618 if(inputVisible)
619 this.parentObject.inputbox.focus();
f121b688
CP
620
621 if(this.type == qwebirc.ui.WINDOW_CHANNEL && this.nicksColoured != this.parentObject.uiOptions.NICK_COLOURS) {
622 this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS;
623
624 var nodes = this.nicklist.childNodes;
625 if(this.parentObject.uiOptions.NICK_COLOURS) {
626 for(var i=0;i<nodes.length;i++) {
627 var e = nodes[i], span = e.firstChild;
628 var colour = e.realNick.toHSBColour(this.client);
629 if($defined(colour))
630 span.setStyle("color", colour.rgbToHex());
631 };
632 } else {
633 for(var i=0;i<nodes.length;i++) {
634 var span = nodes[i].firstChild;
635 span.setStyle("color", null);
636 };
637 }
638 }
f4ae92cc
CP
639 },
640 deselect: function() {
641 this.parent();
642
f4ae92cc
CP
643 this.tab.removeClass("tab-selected");
644 this.tab.addClass("tab-unselected");
645 },
646 close: function() {
647 this.parent();
648
f4ae92cc 649 this.parentObject.tabs.removeChild(this.tab);
ff1c78b3
CP
650 this.parentObject.tabs.removeChild(this.spaceNode);
651 this.reflow();
f4ae92cc 652 },
b35116e2 653 addLine: function(type, line, colourClass) {
f4ae92cc
CP
654 var e = new Element("div");
655
b35116e2
CP
656 if(colourClass) {
657 e.addClass(colourClass);
f4ae92cc
CP
658 } else if(this.lastcolour) {
659 e.addClass("linestyle1");
660 } else {
661 e.addClass("linestyle2");
662 }
f4ae92cc 663 this.lastcolour = !this.lastcolour;
35155ba7 664
b35116e2 665 this.parent(type, line, colourClass, e);
be0bd774
CP
666 },
667 setHilighted: function(state) {
2a802692 668 var laststate = this.hilighted;
96f28062 669
be0bd774 670 this.parent(state);
96f28062
CP
671
672 if(state == laststate)
673 return;
674
675 this.tab.removeClass("tab-hilight-activity");
676 this.tab.removeClass("tab-hilight-us");
677 this.tab.removeClass("tab-hilight-speech");
f4ae92cc 678
96f28062
CP
679 switch(this.hilighted) {
680 case qwebirc.ui.HILIGHT_US:
681 this.tab.addClass("tab-hilight-us");
682 break;
683 case qwebirc.ui.HILIGHT_SPEECH:
684 this.tab.addClass("tab-hilight-speech");
685 break;
686 case qwebirc.ui.HILIGHT_ACTIVITY:
687 this.tab.addClass("tab-hilight-activity");
688 break;
be0bd774 689 }
a4a71818
CP
690 },
691 setSideTabs: function(value) {
692 if(this.tabclose === null)
693 return;
694 this.tab.removeChild(this.tabclose);
695 if(value) {
696 this.tab.insertBefore(this.tabclose, this.tab.firstChild);
697 } else {
698 this.tab.appendChild(this.tabclose);
699 }
f4ae92cc
CP
700 }
701});