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