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