]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/frontends/qui.js
add shift+tab to go back through tab completion
[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 });
710fd882
CP
192
193 var reset = this.resetTabComplete.bind(this);
194 inputbox.addEvent("focus", reset);
195 inputbox.addEvent("mousedown", reset);
196 inputbox.addEvent("keypress", reset);
197
e20e5a6b
CP
198 inputbox.addEvent("keydown", function(e) {
199 var resultfn;
200 var cvalue = inputbox.value;
710fd882
CP
201
202 if(e.alt || e.control || e.meta)
203 return;
204
205 if(e.key == "up" && !e.shift) {
e20e5a6b 206 resultfn = this.commandhistory.upLine;
710fd882 207 } else if(e.key == "down" && !e.shift) {
e20e5a6b 208 resultfn = this.commandhistory.downLine;
710fd882
CP
209 } else if(e.key == "tab") {
210 this.tabComplete(inputbox, e.shift);
211
3184781b 212 new Event(e).stop();
710fd882 213 e.preventDefault();
3184781b 214 return;
e20e5a6b
CP
215 } else {
216 return;
217 }
218
3184781b 219 this.resetTabComplete();
e20e5a6b
CP
220 if((cvalue != "") && (this.lastcvalue != cvalue))
221 this.commandhistory.addLine(cvalue, true);
222
223 var result = resultfn.bind(this.commandhistory)();
224
225 new Event(e).stop();
710fd882
CP
226 e.preventDefault();
227
e20e5a6b
CP
228 if(!result)
229 result = "";
230 this.lastcvalue = result;
231
232 inputbox.value = result;
1d6756bc 233 qwebirc.util.setAtEnd(inputbox);
e20e5a6b
CP
234 }.bind(this));
235 },
236 setLines: function(lines) {
237 this.lines.parentNode.replaceChild(lines, this.lines);
238 this.qjsui.middle = this.lines = lines;
239 },
240 setChannelItems: function(nicklist, topic) {
241 if(!$defined(nicklist)) {
242 nicklist = this.orignicklist;
243 topic = this.origtopic;
244 }
245 this.nicklist.parentNode.replaceChild(nicklist, this.nicklist);
246 this.qjsui.right = this.nicklist = nicklist;
247
248 this.topic.parentNode.replaceChild(topic, this.topic);
249 this.qjsui.topic = this.topic = topic;
a4a71818
CP
250 },
251 setSideTabs: function(value) {
252 if(value === this.sideTabs)
253 return;
254
255 if(this.sideTabs === true) {
256 this.qjsui.left.removeChild(this.outerTabs);
257 } else if(this.sideTabs === false) {
258 this.qjsui.top.removeChild(this.outerTabs);
259 }
260 if(value) {
261 this.qjsui.left.appendChild(this.outerTabs);
262 this.qjsui.top.style.display = "none";
263 this.qjsui.left.style.display = "";
264 } else {
265 this.qjsui.top.appendChild(this.outerTabs);
266 this.qjsui.top.style.display = "";
267 this.qjsui.left.style.display = "none";
268 }
269 this.sideTabs = value;
270 this.windows.each(function(k, v) {
271 v.each(function(k, v2) {
272 v2.setSideTabs(value);
273 });
274 });
e20e5a6b
CP
275 }
276});
277
278qwebirc.ui.QUI.JSUI = new Class({
bfbe72f9 279 Implements: [Events],
b1ee83f3
CP
280 initialize: function(class_, parent, sizer) {
281 this.parent = parent;
282 this.sizer = $defined(sizer)?sizer:parent;
a4a71818 283
24ede2cb
CP
284 this.class_ = class_;
285 this.create();
286
6c19eb8f
CP
287 this.reflowevent = null;
288
b1ee83f3 289 window.addEvent("resize", function() {
6c19eb8f 290 this.reflow(100);
b1ee83f3
CP
291 }.bind(this));
292 },
24ede2cb 293 applyClasses: function(pos, l) {
6c19eb8f 294 l.addClass("dynamicpanel");
24ede2cb 295 l.addClass(this.class_);
a4a71818 296 l.addClass(pos + "boundpanel");
24ede2cb
CP
297 },
298 create: function() {
299 var XE = function(pos) {
300 var element = new Element("div");
301 this.applyClasses(pos, element);
b1ee83f3 302
24ede2cb
CP
303 this.parent.appendChild(element);
304 return element;
b1ee83f3
CP
305 }.bind(this);
306
24ede2cb 307 this.top = XE("top");
a4a71818 308 this.left = XE("left");
24ede2cb
CP
309 this.topic = XE("topic");
310 this.middle = XE("middle");
311 this.right = XE("right");
312 this.bottom = XE("bottom");
b1ee83f3 313 },
6c19eb8f
CP
314 reflow: function(delay) {
315 if(!delay)
316 delay = 1;
317
318 if(this.reflowevent)
319 $clear(this.reflowevent);
320 this.__reflow();
321 this.reflowevent = this.__reflow.delay(delay, this);
322 },
323 __reflow: function() {
b1ee83f3
CP
324 var bottom = this.bottom;
325 var middle = this.middle;
326 var right = this.right;
327 var topic = this.topic;
328 var top = this.top;
a4a71818
CP
329 var left = this.left;
330
331 /* |----------------------------------------------|
332 * | top |
333 * |----------------------------------------------|
334 * | left | topic | right |
335 * | |-------------------------------| |
336 * | | middle | |
337 * | | | |
338 * | | | |
339 * | |---------------------------------------|
340 * | | bottom |
341 * |----------------------------------------------|
342 */
343
b1ee83f3
CP
344 var topicsize = topic.getSize();
345 var topsize = top.getSize();
346 var rightsize = right.getSize();
347 var bottomsize = bottom.getSize();
a4a71818 348 var leftsize = left.getSize();
b1ee83f3
CP
349 var docsize = this.sizer.getSize();
350
351 var mheight = (docsize.y - topsize.y - bottomsize.y - topicsize.y);
6e18a495 352 var mwidth = (docsize.x - rightsize.x - leftsize.x);
b1ee83f3 353
a4a71818 354 left.setStyle("top", topsize.y);
4b9f894d 355 topic.setStyle("top", topsize.y);
a4a71818 356 topic.setStyle("left", leftsize.x);
970463d9 357 topic.setStyle("width", docsize.x - leftsize.x);
b1ee83f3 358
4b9f894d 359 middle.setStyle("top", (topsize.y + topicsize.y));
a4a71818 360 middle.setStyle("left", leftsize.x);
b1ee83f3 361 if(mheight > 0) {
4b9f894d
CP
362 middle.setStyle("height", mheight);
363 right.setStyle("height", mheight);
b1ee83f3
CP
364 }
365
6c19eb8f 366 if(mwidth > 0)
4b9f894d
CP
367 middle.setStyle("width", mwidth);
368 right.setStyle("top", (topsize.y + topicsize.y));
a4a71818
CP
369
370 bottom.setStyle("left", leftsize.x);
bfbe72f9 371 this.fireEvent("reflow");
b1ee83f3 372 },
5f464ed5 373 showChannel: function(state, nicklistVisible) {
b1ee83f3
CP
374 var display = "none";
375 if(state)
376 display = "block";
377
5f464ed5 378 this.right.setStyle("display", nicklistVisible ? display : "none");
b1ee83f3 379 this.topic.setStyle("display", display);
6c19eb8f
CP
380 },
381 showInput: function(state) {
941e1642 382 this.bottom.isVisible = state;
6c19eb8f 383 this.bottom.setStyle("display", state?"block":"none");
b1ee83f3
CP
384 }
385});
35155ba7 386
e20e5a6b
CP
387qwebirc.ui.QUI.Window = new Class({
388 Extends: qwebirc.ui.Window,
f4ae92cc 389
f74802c5
CP
390 initialize: function(parentObject, client, type, name, identifier) {
391 this.parent(parentObject, client, type, name, identifier);
be0bd774 392
cb9d1c92 393 this.tab = new Element("a");
f4ae92cc 394 this.tab.addClass("tab");
fd60516d 395 this.tab.addEvent("focus", function() { this.blur() }.bind(this.tab));;
ff1c78b3
CP
396
397 this.spaceNode = document.createTextNode(" ");
35155ba7 398 parentObject.tabs.appendChild(this.tab);
ff1c78b3 399 parentObject.tabs.appendChild(this.spaceNode);
a4a71818 400
e20e5a6b
CP
401 if(type != qwebirc.ui.WINDOW_STATUS && type != qwebirc.ui.WINDOW_CONNECT) {
402 var tabclose = new Element("span");
a4a71818 403 this.tabclose = tabclose;
e20e5a6b 404 tabclose.set("text", "X");
f4ae92cc 405 tabclose.addClass("tabclose");
f84bf379 406 var close = function(e) {
f4ae92cc 407 new Event(e).stop();
a4a71818 408
f84bf379
CP
409 if(this.closed)
410 return;
a4a71818 411
e20e5a6b 412 if(type == qwebirc.ui.WINDOW_CHANNEL)
f4ae92cc
CP
413 this.client.exec("/PART " + name);
414
415 this.close();
a4a71818 416
941e1642 417 //parentObject.inputbox.focus();
f84bf379 418 }.bind(this);
a4a71818 419
f84bf379
CP
420 tabclose.addEvent("click", close);
421 this.tab.addEvent("mouseup", function(e) {
b46f79e6 422 var button = 1;
a4a71818 423
b46f79e6
CP
424 if(Browser.Engine.trident)
425 button = 4;
426
427 if(e.event.button == button)
f84bf379 428 close(e);
f4ae92cc 429 }.bind(this));
a4a71818 430
f4ae92cc 431 this.tab.appendChild(tabclose);
a4a71818
CP
432 } else {
433 this.tabclose = null;
f4ae92cc 434 }
be0bd774 435
a4a71818
CP
436 this.tab.appendText(name);
437 this.tab.addEvent("click", function(e) {
438 new Event(e).stop();
439
440 if(this.closed)
441 return;
442
443 parentObject.selectWindow(this);
444 }.bind(this));
445
446
be0bd774 447 this.lines = new Element("div");
6c19eb8f 448 this.parentObject.qjsui.applyClasses("middle", this.lines);
be0bd774 449 this.lines.addClass("lines");
e82478eb
CP
450 if(type != qwebirc.ui.WINDOW_CUSTOM && type != qwebirc.ui.WINDOW_CONNECT)
451 this.lines.addClass("ircwindow");
6c19eb8f 452
b1ee83f3
CP
453 this.lines.addEvent("scroll", function() {
454 this.scrolleddown = this.scrolledDown();
ff6a32cc 455 this.scrollpos = this.getScrollParent().getScroll();
be0bd774 456 }.bind(this));
be0bd774 457
2326e8d5 458 if(type == qwebirc.ui.WINDOW_CHANNEL || type == qwebirc.ui.WINDOW_QUERY) {
be0bd774 459 this.topic = new Element("div");
a4a71818 460 this.parentObject.qjsui.applyClasses("topic", this.topic);
be0bd774 461 this.topic.addClass("topic");
b1ee83f3 462 this.topic.addClass("tab-invisible");
be0bd774 463 this.topic.set("html", "&nbsp;");
8eb4377c 464 this.topic.addEvent("dblclick", this.editTopic.bind(this));
6c19eb8f 465 this.parentObject.qjsui.applyClasses("topic", this.topic);
2326e8d5 466
52090a1f 467 this.prevNick = null;
66de775f
CP
468 this.nicklist = new Element("div");
469 this.nicklist.addClass("nicklist");
b1ee83f3 470 this.nicklist.addClass("tab-invisible");
cffd43cf 471 this.nicklist.addEvent("click", this.removePrevMenu.bind(this));
a4a71818 472 this.parentObject.qjsui.applyClasses("right", this.nicklist);
2326e8d5
CP
473
474 this.updateTopic("");
be0bd774 475 }
b1ee83f3 476
f121b688 477 this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS;
a4a71818 478 this.reflow();
b1ee83f3 479 },
5aa173fb 480 rename: function(name) {
2326e8d5
CP
481 var newNode = document.createTextNode(name);
482 if(this.parentObject.sideTabs) {
483 this.tab.replaceChild(newNode, this.tab.childNodes[1]);
484 } else {
485 this.tab.replaceChild(newNode, this.tab.firstChild);
486 }
487
488 if(this.type == qwebirc.ui.WINDOW_QUERY)
489 this.updateTopic("");
5aa173fb 490 },
eaf3ed38 491 editTopic: function() {
2326e8d5
CP
492 if(this.type != qwebirc.ui.WINDOW_CHANNEL)
493 return;
494
eaf3ed38
CP
495 if(!this.client.nickOnChanHasPrefix(this.client.nickname, this.name, "@")) {
496/* var cmodes = this.client.getChannelModes(channel);
497 if(cmodes.indexOf("t")) {*/
95d00e97 498 alert("Sorry, you need to be a channel operator to change the topic!");
eaf3ed38
CP
499 return;
500 /*}*/
501 }
502 var newTopic = prompt("Change topic of " + this.name + " to:", this.topic.topicText);
503 if(newTopic === null)
504 return;
505
506 this.client.exec("/TOPIC " + newTopic);
507 },
b1ee83f3
CP
508 reflow: function() {
509 this.parentObject.reflow();
35155ba7
CP
510 },
511 onResize: function() {
ff6a32cc
CP
512 if(this.scrolleddown) {
513 if(Browser.Engine.trident) {
514 this.scrollToBottom.delay(5, this);
515 } else {
516 this.scrollToBottom();
517 }
518 } else if($defined(this.scrollpos)) {
519 if(Browser.Engine.trident) {
520 this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y);
521 } else {
522 this.getScrollParent().scrollTo.delay(5, this, [this.scrollpos.x, this.scrollpos.y]);
523 }
524 }
359b7edd 525 },
cffd43cf 526 createMenu: function(nick, parent) {
d2512acf 527 var e = new Element("div");
cffd43cf
CP
528 parent.appendChild(e);
529 e.addClass("menu");
530
27add99a 531 var nickArray = [nick];
cffd43cf 532 qwebirc.ui.MENU_ITEMS.forEach(function(x) {
27add99a
CP
533 if(!x.predicate || x.predicate !== true && !x.predicate.apply(this, nickArray))
534 return;
535
536 var e2 = new Element("a");
537 e.appendChild(e2);
7555d601 538
27add99a 539 e2.set("text", "- " + x.text);
7555d601 540
27add99a
CP
541 e2.addEvent("focus", function() { this.blur() }.bind(e2));
542 e2.addEvent("click", function(ev) { new Event(ev.stop()); this.menuClick(x.fn); }.bind(this));
cffd43cf
CP
543 }.bind(this));
544 return e;
545 },
546 menuClick: function(fn) {
547 /*
548 this.prevNick.removeChild(this.prevNick.menu);
549 this.prevNick.menu = null;
550 */
551 fn.bind(this)(this.prevNick.realNick);
552 this.removePrevMenu();
553 },
d8272bcb
CP
554 moveMenuClass: function() {
555 if(!this.prevNick)
556 return;
557 if(this.nicklist.firstChild == this.prevNick) {
558 this.prevNick.removeClass("selected-middle");
559 } else {
560 this.prevNick.addClass("selected-middle");
561 }
562 },
cffd43cf
CP
563 removePrevMenu: function() {
564 if(!this.prevNick)
565 return;
566
567 this.prevNick.removeClass("selected");
d8272bcb 568 this.prevNick.removeClass("selected-middle");
cffd43cf
CP
569 if(this.prevNick.menu)
570 this.prevNick.removeChild(this.prevNick.menu);
571 this.prevNick = null;
572 },
52090a1f 573 nickListAdd: function(nick, position) {
f121b688
CP
574 var realNick = this.client.stripPrefix(nick);
575
52090a1f
CP
576 var e = new Element("a");
577 qwebirc.ui.insertAt(position, this.nicklist, e);
f121b688
CP
578 var span = new Element("span");
579 if(this.parentObject.uiOptions.NICK_COLOURS) {
580 var colour = realNick.toHSBColour(this.client);
581 if($defined(colour))
582 span.setStyle("color", colour.rgbToHex());
583 }
584 span.set("text", nick);
585 e.appendChild(span);
52090a1f 586
f121b688 587 e.realNick = realNick;
52090a1f
CP
588
589 e.addEvent("click", function(x) {
aab6d06a
CP
590 if(this.prevNick == e) {
591 this.removePrevMenu();
592 return;
593 }
594
cffd43cf 595 this.removePrevMenu();
52090a1f
CP
596 this.prevNick = e;
597 e.addClass("selected");
d8272bcb 598 this.moveMenuClass();
27add99a 599 e.menu = this.createMenu(e.realNick, e);
52090a1f
CP
600 new Event(x).stop();
601 }.bind(this));
52090a1f 602
fd60516d 603 e.addEvent("focus", function() { this.blur() }.bind(e));
d8272bcb 604 this.moveMenuClass();
52090a1f
CP
605 return e;
606 },
607 nickListRemove: function(nick, stored) {
608 this.nicklist.removeChild(stored);
d8272bcb 609 this.moveMenuClass();
f4ae92cc
CP
610 },
611 updateTopic: function(topic) {
f4ae92cc
CP
612 var t = this.topic;
613
614 while(t.firstChild)
615 t.removeChild(t.firstChild);
616
2326e8d5
CP
617 var suffix;
618 if(this.type == qwebirc.ui.WINDOW_CHANNEL) {
619 suffix = ": ";
66de775f 620 } else {
2326e8d5
CP
621 suffix = "";
622 }
623 qwebirc.ui.Colourise(this.name + suffix, t, null, null, this);
624
625 if(this.type == qwebirc.ui.WINDOW_CHANNEL) {
eaf3ed38 626 t.topicText = topic;
2326e8d5
CP
627 if (topic) {
628 this.parent(topic, t);
629 } else {
630 t.appendChild(document.createTextNode("(no topic set)"));
631 }
66de775f 632 }
2326e8d5 633
359b7edd 634 this.reflow();
f4ae92cc
CP
635 },
636 select: function() {
e20e5a6b 637 var inputVisible = this.type != qwebirc.ui.WINDOW_CONNECT && this.type != qwebirc.ui.WINDOW_CUSTOM;
6c19eb8f 638
f4ae92cc 639 this.tab.removeClass("tab-unselected");
f4ae92cc 640 this.tab.addClass("tab-selected");
359b7edd 641
6c19eb8f
CP
642 this.parentObject.setLines(this.lines);
643 this.parentObject.setChannelItems(this.nicklist, this.topic);
644 this.parentObject.qjsui.showInput(inputVisible);
5f464ed5 645 this.parentObject.qjsui.showChannel($defined(this.nicklist), this.parentObject.uiOptions.SHOW_NICKLIST);
6c19eb8f
CP
646
647 this.reflow();
24ede2cb 648
7c633700 649 this.parent();
25be5960 650
6c19eb8f
CP
651 if(inputVisible)
652 this.parentObject.inputbox.focus();
f121b688
CP
653
654 if(this.type == qwebirc.ui.WINDOW_CHANNEL && this.nicksColoured != this.parentObject.uiOptions.NICK_COLOURS) {
655 this.nicksColoured = this.parentObject.uiOptions.NICK_COLOURS;
656
657 var nodes = this.nicklist.childNodes;
658 if(this.parentObject.uiOptions.NICK_COLOURS) {
659 for(var i=0;i<nodes.length;i++) {
660 var e = nodes[i], span = e.firstChild;
661 var colour = e.realNick.toHSBColour(this.client);
662 if($defined(colour))
663 span.setStyle("color", colour.rgbToHex());
664 };
665 } else {
666 for(var i=0;i<nodes.length;i++) {
667 var span = nodes[i].firstChild;
668 span.setStyle("color", null);
669 };
670 }
671 }
f4ae92cc
CP
672 },
673 deselect: function() {
674 this.parent();
675
f4ae92cc
CP
676 this.tab.removeClass("tab-selected");
677 this.tab.addClass("tab-unselected");
678 },
679 close: function() {
680 this.parent();
681
f4ae92cc 682 this.parentObject.tabs.removeChild(this.tab);
ff1c78b3
CP
683 this.parentObject.tabs.removeChild(this.spaceNode);
684 this.reflow();
f4ae92cc 685 },
b35116e2 686 addLine: function(type, line, colourClass) {
f4ae92cc
CP
687 var e = new Element("div");
688
b35116e2
CP
689 if(colourClass) {
690 e.addClass(colourClass);
f4ae92cc
CP
691 } else if(this.lastcolour) {
692 e.addClass("linestyle1");
693 } else {
694 e.addClass("linestyle2");
695 }
f4ae92cc 696 this.lastcolour = !this.lastcolour;
35155ba7 697
b35116e2 698 this.parent(type, line, colourClass, e);
be0bd774
CP
699 },
700 setHilighted: function(state) {
2a802692 701 var laststate = this.hilighted;
96f28062 702
be0bd774 703 this.parent(state);
96f28062
CP
704
705 if(state == laststate)
706 return;
707
708 this.tab.removeClass("tab-hilight-activity");
709 this.tab.removeClass("tab-hilight-us");
710 this.tab.removeClass("tab-hilight-speech");
f4ae92cc 711
96f28062
CP
712 switch(this.hilighted) {
713 case qwebirc.ui.HILIGHT_US:
714 this.tab.addClass("tab-hilight-us");
715 break;
716 case qwebirc.ui.HILIGHT_SPEECH:
717 this.tab.addClass("tab-hilight-speech");
718 break;
719 case qwebirc.ui.HILIGHT_ACTIVITY:
720 this.tab.addClass("tab-hilight-activity");
721 break;
be0bd774 722 }
a4a71818
CP
723 },
724 setSideTabs: function(value) {
725 if(this.tabclose === null)
726 return;
727 this.tab.removeChild(this.tabclose);
728 if(value) {
729 this.tab.insertBefore(this.tabclose, this.tab.firstChild);
730 } else {
731 this.tab.appendChild(this.tabclose);
732 }
f4ae92cc
CP
733 }
734});