]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/frontends/qui.js
Make our nick in our own messages bold.
[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;
7 },
8 postInitialize: function() {
9 this.qjsui = new qwebirc.ui.QUI.JSUI("qwebirc-qui", this.parentElement);
bfbe72f9
CP
10 this.qjsui.addEvent("reflow", function() {
11 var w = this.getActiveWindow();
12 if($defined(w))
13 w.onResize();
14 }.bind(this));
941e1642 15 this.qjsui.top.addClass("outertabbar");
e20e5a6b
CP
16
17 this.qjsui.bottom.addClass("input");
18 this.qjsui.right.addClass("nicklist");
19 this.qjsui.topic.addClass("topic");
20 this.qjsui.middle.addClass("lines");
21
941e1642 22 this.outerTabs = this.qjsui.top;
0989d983 23
941e1642
CP
24 this.tabs = new Element("div");
25 this.tabs.addClass("tabbar");
9da8639a
CP
26
27 this.__createDropdownMenu();
28
941e1642 29 this.outerTabs.appendChild(this.tabs);
e20e5a6b
CP
30 this.origtopic = this.topic = this.qjsui.topic;
31 this.origlines = this.lines = this.qjsui.middle;
32 this.orignicklist = this.nicklist = this.qjsui.right;
33
34 this.input = this.qjsui.bottom;
35 this.reflow = this.qjsui.reflow.bind(this.qjsui);
36
ff4befd8
CP
37 this.tabs.addEvent("mousewheel", function(x) {
38 var event = new Event(x);
39
40 /* up */
41 if(event.wheel > 0) {
42 this.nextWindow();
43 } else if(event.wheel < 0) {
44 /* down */
b35116e2 45 this.prevWindow();
ff4befd8
CP
46 }
47 event.stop();
48 }.bind(this));
49
e20e5a6b
CP
50 this.createInput();
51 this.reflow();
0a55be30
CP
52 this.reflow.delay(100); /* Konqueror fix */
53
9da8639a
CP
54 /* HACK, in Chrome this should work immediately but doesn't */
55 this.__createDropdownHint.delay(100, this);
e20e5a6b 56 },
0989d983 57 __createDropdownMenu: function() {
e9837dce 58 var dropdownMenu = new Element("span");
43cb8910 59 dropdownMenu.addClass("dropdownmenu");
0989d983
CP
60
61 dropdownMenu.hide = function() {
43cb8910
CP
62 dropdownMenu.setStyle("display", "none");
63 dropdownMenu.visible = false;
e9837dce 64 document.removeEvent("mousedown", hideEvent);
43cb8910 65 }.bind(this);
e9837dce 66 var hideEvent = function() { dropdownMenu.hide(); };
0989d983
CP
67
68 dropdownMenu.hide();
43cb8910
CP
69 this.parentElement.appendChild(dropdownMenu);
70
71 this.UICommands.forEach(function(x) {
72 var text = x[0];
73 var fn = this[x[1] + "Window"].bind(this);
74 var e = new Element("a");
0989d983 75 e.addEvent("mousedown", function(e) { new Event(e).stop(); });
43cb8910
CP
76 e.addEvent("click", function() {
77 dropdownMenu.hide();
78 fn();
79 });
80 e.set("text", text);
81 dropdownMenu.appendChild(e);
82 }.bind(this));
83
941e1642 84 var dropdown = new Element("div");
43cb8910 85 dropdown.addClass("dropdown-tab");
941e1642 86 dropdown.appendChild(new Element("img", {src: "images/favicon.png", title: "menu", alt: "menu"}));
391f51ff
CP
87 dropdown.setStyle("opacity", 1);
88
89 var dropdownEffect = new Fx.Tween(dropdown, {duration: "long", property: "opacity", link: "chain"});
90 dropdownEffect.start(0.25);
91 dropdownEffect.start(1);
92 dropdownEffect.start(0.33);
93 dropdownEffect.start(1);
94
941e1642 95 this.outerTabs.appendChild(dropdown);
9da8639a 96 dropdownMenu.show = function(x) {
43cb8910 97 new Event(x).stop();
e9837dce 98 this.hideHint();
43cb8910
CP
99
100 if(dropdownMenu.visible) {
101 dropdownMenu.hide();
102 return;
103 }
e9837dce
CP
104 var top = this.outerTabs.getSize().y;
105
941e1642 106 dropdownMenu.setStyle("left", 0);
385143a6 107 dropdownMenu.setStyle("top", top-1); /* -1 == top border */
43cb8910
CP
108 dropdownMenu.setStyle("display", "inline-block");
109 dropdownMenu.visible = true;
e9837dce
CP
110
111 document.addEvent("mousedown", hideEvent);
43cb8910 112 }.bind(this);
e9837dce 113 dropdown.addEvent("mousedown", function(e) { new Event(e).stop(); });
43cb8910 114 dropdown.addEvent("click", dropdownMenu.show);
0989d983 115 },
9da8639a 116 __createDropdownHint: function() {
43cb8910
CP
117 var dropdownhint = new Element("div");
118 dropdownhint.addClass("dropdownhint");
391f51ff 119 dropdownhint.set("text", "Click the icon for the main menu.");
e9837dce
CP
120 dropdownhint.setStyle("top", this.outerTabs.getSize().y + 5);
121
122 this.parentElement.appendChild(dropdownhint);
391f51ff
CP
123 new Fx.Morph(dropdownhint, {duration: "normal", transition: Fx.Transitions.Sine.easeOut}).start({left: [900, 5]});
124
43cb8910 125 var hider = function() {
391f51ff
CP
126 new Fx.Morph(dropdownhint, {duration: "long"}).start({left: [5, -900]});
127 }.delay(4000, this);
0989d983 128
391f51ff
CP
129 var hider2 = function() {
130 if(dropdownhint.hidden)
131 return;
e9837dce 132 this.parentElement.removeChild(dropdownhint);
391f51ff
CP
133 dropdownhint.hidden = 1;
134 }.bind(this);
135 hider2.delay(4000);
e9837dce 136 this.hideHint = hider2;
391f51ff
CP
137
138 document.addEvent("mousedown", hider2);
139 document.addEvent("keypress", hider2);
140
43cb8910 141 },
e20e5a6b
CP
142 createInput: function() {
143 var form = new Element("form");
144 this.input.appendChild(form);
145 form.addClass("input");
146
147 var inputbox = new Element("input");
148 form.appendChild(inputbox);
149 this.inputbox = inputbox;
2589dfb0 150 this.inputbox.maxLength = 512;
e20e5a6b
CP
151
152 form.addEvent("submit", function(e) {
153 new Event(e).stop();
154
155 if(inputbox.value == "")
156 return;
157
3184781b 158 this.resetTabComplete();
e20e5a6b
CP
159 this.getActiveWindow().historyExec(inputbox.value);
160 inputbox.value = "";
161 }.bind(this));
162
3184781b
CP
163 inputbox.addEvent("focus", this.resetTabComplete.bind(this));
164 inputbox.addEvent("mousedown", this.resetTabComplete.bind(this));
165
e20e5a6b
CP
166 inputbox.addEvent("keydown", function(e) {
167 var resultfn;
168 var cvalue = inputbox.value;
3184781b 169
e20e5a6b
CP
170 if(e.key == "up") {
171 resultfn = this.commandhistory.upLine;
172 } else if(e.key == "down") {
173 resultfn = this.commandhistory.downLine;
3184781b
CP
174 } else if(e.key == "tab") {
175 new Event(e).stop();
176 this.tabComplete(inputbox);
177 return;
e20e5a6b 178 } else {
3184781b
CP
179 /* ideally alt and other keys wouldn't break this */
180 this.resetTabComplete();
e20e5a6b
CP
181 return;
182 }
183
3184781b 184 this.resetTabComplete();
e20e5a6b
CP
185 if((cvalue != "") && (this.lastcvalue != cvalue))
186 this.commandhistory.addLine(cvalue, true);
187
188 var result = resultfn.bind(this.commandhistory)();
189
190 new Event(e).stop();
191 if(!result)
192 result = "";
193 this.lastcvalue = result;
194
195 inputbox.value = result;
1d6756bc 196 qwebirc.util.setAtEnd(inputbox);
e20e5a6b
CP
197 }.bind(this));
198 },
199 setLines: function(lines) {
200 this.lines.parentNode.replaceChild(lines, this.lines);
201 this.qjsui.middle = this.lines = lines;
202 },
203 setChannelItems: function(nicklist, topic) {
204 if(!$defined(nicklist)) {
205 nicklist = this.orignicklist;
206 topic = this.origtopic;
207 }
208 this.nicklist.parentNode.replaceChild(nicklist, this.nicklist);
209 this.qjsui.right = this.nicklist = nicklist;
210
211 this.topic.parentNode.replaceChild(topic, this.topic);
212 this.qjsui.topic = this.topic = topic;
213 }
214});
215
216qwebirc.ui.QUI.JSUI = new Class({
bfbe72f9 217 Implements: [Events],
b1ee83f3
CP
218 initialize: function(class_, parent, sizer) {
219 this.parent = parent;
220 this.sizer = $defined(sizer)?sizer:parent;
221
24ede2cb
CP
222 this.class_ = class_;
223 this.create();
224
6c19eb8f
CP
225 this.reflowevent = null;
226
b1ee83f3 227 window.addEvent("resize", function() {
6c19eb8f 228 this.reflow(100);
b1ee83f3
CP
229 }.bind(this));
230 },
24ede2cb 231 applyClasses: function(pos, l) {
6c19eb8f 232 l.addClass("dynamicpanel");
24ede2cb 233 l.addClass(this.class_);
6c19eb8f 234
24ede2cb
CP
235 if(pos == "middle") {
236 l.addClass("leftboundpanel");
237 } else if(pos == "top") {
238 l.addClass("topboundpanel");
239 l.addClass("widepanel");
240 } else if(pos == "topic") {
241 l.addClass("widepanel");
242 } else if(pos == "right") {
243 l.addClass("rightboundpanel");
244 } else if(pos == "bottom") {
245 l.addClass("bottomboundpanel");
246 l.addClass("widepanel");
247 }
248 },
249 create: function() {
250 var XE = function(pos) {
251 var element = new Element("div");
252 this.applyClasses(pos, element);
b1ee83f3 253
24ede2cb
CP
254 this.parent.appendChild(element);
255 return element;
b1ee83f3
CP
256 }.bind(this);
257
24ede2cb
CP
258 this.top = XE("top");
259 this.topic = XE("topic");
260 this.middle = XE("middle");
261 this.right = XE("right");
262 this.bottom = XE("bottom");
b1ee83f3 263 },
6c19eb8f
CP
264 reflow: function(delay) {
265 if(!delay)
266 delay = 1;
267
268 if(this.reflowevent)
269 $clear(this.reflowevent);
270 this.__reflow();
271 this.reflowevent = this.__reflow.delay(delay, this);
272 },
273 __reflow: function() {
b1ee83f3
CP
274 var bottom = this.bottom;
275 var middle = this.middle;
276 var right = this.right;
277 var topic = this.topic;
278 var top = this.top;
279
280 var topicsize = topic.getSize();
281 var topsize = top.getSize();
282 var rightsize = right.getSize();
283 var bottomsize = bottom.getSize();
284 var docsize = this.sizer.getSize();
285
286 var mheight = (docsize.y - topsize.y - bottomsize.y - topicsize.y);
287 var mwidth = (docsize.x - rightsize.x);
288
4b9f894d 289 topic.setStyle("top", topsize.y);
b1ee83f3 290
4b9f894d 291 middle.setStyle("top", (topsize.y + topicsize.y));
b1ee83f3 292 if(mheight > 0) {
4b9f894d
CP
293 middle.setStyle("height", mheight);
294 right.setStyle("height", mheight);
b1ee83f3
CP
295 }
296
6c19eb8f 297 if(mwidth > 0)
4b9f894d
CP
298 middle.setStyle("width", mwidth);
299 right.setStyle("top", (topsize.y + topicsize.y));
300 right.setStyle("left", mwidth);
b1ee83f3 301
4b9f894d 302 bottom.setStyle("top", (docsize.y - bottomsize.y));
bfbe72f9 303 this.fireEvent("reflow");
b1ee83f3
CP
304 },
305 showChannel: function(state) {
306 var display = "none";
307 if(state)
308 display = "block";
309
310 this.right.setStyle("display", display);
311 this.topic.setStyle("display", display);
6c19eb8f
CP
312 },
313 showInput: function(state) {
941e1642 314 this.bottom.isVisible = state;
6c19eb8f 315 this.bottom.setStyle("display", state?"block":"none");
b1ee83f3
CP
316 }
317});
35155ba7 318
e20e5a6b
CP
319qwebirc.ui.QUI.Window = new Class({
320 Extends: qwebirc.ui.Window,
f4ae92cc 321
f74802c5
CP
322 initialize: function(parentObject, client, type, name, identifier) {
323 this.parent(parentObject, client, type, name, identifier);
be0bd774 324
66de775f 325 this.tab = new Element("a", {"href": "#"});
f4ae92cc 326 this.tab.addClass("tab");
fd60516d
CP
327 this.tab.addEvent("focus", function() { this.blur() }.bind(this.tab));;
328
35155ba7 329 parentObject.tabs.appendChild(this.tab);
f4ae92cc
CP
330
331 this.tab.appendText(name);
66de775f
CP
332 this.tab.addEvent("click", function(e) {
333 new Event(e).stop();
f84bf379
CP
334
335 if(this.closed)
336 return;
337
f4ae92cc
CP
338 parentObject.selectWindow(this);
339 }.bind(this));
f4ae92cc 340
e20e5a6b
CP
341 if(type != qwebirc.ui.WINDOW_STATUS && type != qwebirc.ui.WINDOW_CONNECT) {
342 var tabclose = new Element("span");
343 tabclose.set("text", "X");
f4ae92cc 344 tabclose.addClass("tabclose");
f84bf379 345 var close = function(e) {
f4ae92cc
CP
346 new Event(e).stop();
347
f84bf379
CP
348 if(this.closed)
349 return;
350
e20e5a6b 351 if(type == qwebirc.ui.WINDOW_CHANNEL)
f4ae92cc
CP
352 this.client.exec("/PART " + name);
353
354 this.close();
3184781b 355
941e1642 356 //parentObject.inputbox.focus();
f84bf379
CP
357 }.bind(this);
358
359 tabclose.addEvent("click", close);
360 this.tab.addEvent("mouseup", function(e) {
b46f79e6
CP
361 var button = 1;
362
363 if(Browser.Engine.trident)
364 button = 4;
365
366 if(e.event.button == button)
f84bf379 367 close(e);
f4ae92cc 368 }.bind(this));
52090a1f 369
f4ae92cc
CP
370 this.tab.appendChild(tabclose);
371 }
be0bd774 372
be0bd774 373 this.lines = new Element("div");
6c19eb8f 374 this.parentObject.qjsui.applyClasses("middle", this.lines);
be0bd774 375 this.lines.addClass("lines");
e82478eb
CP
376 if(type != qwebirc.ui.WINDOW_CUSTOM && type != qwebirc.ui.WINDOW_CONNECT)
377 this.lines.addClass("ircwindow");
6c19eb8f 378
b1ee83f3
CP
379 this.lines.addEvent("scroll", function() {
380 this.scrolleddown = this.scrolledDown();
ff6a32cc 381 this.scrollpos = this.getScrollParent().getScroll();
be0bd774 382 }.bind(this));
be0bd774 383
e20e5a6b 384 if(type == qwebirc.ui.WINDOW_CHANNEL) {
be0bd774
CP
385 this.topic = new Element("div");
386 this.topic.addClass("topic");
b1ee83f3 387 this.topic.addClass("tab-invisible");
be0bd774 388 this.topic.set("html", "&nbsp;");
eaf3ed38 389 this.topic.addEvent("click", this.editTopic.bind(this));
6c19eb8f 390 this.parentObject.qjsui.applyClasses("topic", this.topic);
be0bd774 391
52090a1f 392 this.prevNick = null;
66de775f
CP
393 this.nicklist = new Element("div");
394 this.nicklist.addClass("nicklist");
b1ee83f3 395 this.nicklist.addClass("tab-invisible");
cffd43cf 396 this.nicklist.addEvent("click", this.removePrevMenu.bind(this));
6c19eb8f 397 this.parentObject.qjsui.applyClasses("nicklist", this.nicklist);
be0bd774 398 }
b1ee83f3 399
e20e5a6b 400 if(type == qwebirc.ui.WINDOW_CHANNEL) {
359b7edd
CP
401 this.updateTopic("");
402 } else {
403 this.reflow();
404 }
b1ee83f3 405 },
eaf3ed38
CP
406 editTopic: function() {
407 if(!this.client.nickOnChanHasPrefix(this.client.nickname, this.name, "@")) {
408/* var cmodes = this.client.getChannelModes(channel);
409 if(cmodes.indexOf("t")) {*/
410 alert("Sorry, you need to be opped to change the topic!");
411 return;
412 /*}*/
413 }
414 var newTopic = prompt("Change topic of " + this.name + " to:", this.topic.topicText);
415 if(newTopic === null)
416 return;
417
418 this.client.exec("/TOPIC " + newTopic);
419 },
b1ee83f3
CP
420 reflow: function() {
421 this.parentObject.reflow();
35155ba7
CP
422 },
423 onResize: function() {
ff6a32cc
CP
424 if(this.scrolleddown) {
425 if(Browser.Engine.trident) {
426 this.scrollToBottom.delay(5, this);
427 } else {
428 this.scrollToBottom();
429 }
430 } else if($defined(this.scrollpos)) {
431 if(Browser.Engine.trident) {
432 this.getScrollParent().scrollTo(this.scrollpos.x, this.scrollpos.y);
433 } else {
434 this.getScrollParent().scrollTo.delay(5, this, [this.scrollpos.x, this.scrollpos.y]);
435 }
436 }
359b7edd 437 },
cffd43cf 438 createMenu: function(nick, parent) {
d2512acf 439 var e = new Element("div");
cffd43cf
CP
440 parent.appendChild(e);
441 e.addClass("menu");
442
27add99a 443 var nickArray = [nick];
cffd43cf 444 qwebirc.ui.MENU_ITEMS.forEach(function(x) {
27add99a
CP
445 if(!x.predicate || x.predicate !== true && !x.predicate.apply(this, nickArray))
446 return;
447
448 var e2 = new Element("a");
449 e.appendChild(e2);
7555d601 450
27add99a
CP
451 e2.href = "#";
452 e2.set("text", "- " + x.text);
7555d601 453
27add99a
CP
454 e2.addEvent("focus", function() { this.blur() }.bind(e2));
455 e2.addEvent("click", function(ev) { new Event(ev.stop()); this.menuClick(x.fn); }.bind(this));
cffd43cf
CP
456 }.bind(this));
457 return e;
458 },
459 menuClick: function(fn) {
460 /*
461 this.prevNick.removeChild(this.prevNick.menu);
462 this.prevNick.menu = null;
463 */
464 fn.bind(this)(this.prevNick.realNick);
465 this.removePrevMenu();
466 },
d8272bcb
CP
467 moveMenuClass: function() {
468 if(!this.prevNick)
469 return;
470 if(this.nicklist.firstChild == this.prevNick) {
471 this.prevNick.removeClass("selected-middle");
472 } else {
473 this.prevNick.addClass("selected-middle");
474 }
475 },
cffd43cf
CP
476 removePrevMenu: function() {
477 if(!this.prevNick)
478 return;
479
480 this.prevNick.removeClass("selected");
d8272bcb 481 this.prevNick.removeClass("selected-middle");
cffd43cf
CP
482 if(this.prevNick.menu)
483 this.prevNick.removeChild(this.prevNick.menu);
484 this.prevNick = null;
485 },
52090a1f
CP
486 nickListAdd: function(nick, position) {
487 var e = new Element("a");
488 qwebirc.ui.insertAt(position, this.nicklist, e);
f4ae92cc 489
52090a1f
CP
490 e.href = "#";
491 e.appendChild(document.createTextNode(nick));
492
493 e.realNick = this.client.stripPrefix(nick);
494
495 e.addEvent("click", function(x) {
aab6d06a
CP
496 if(this.prevNick == e) {
497 this.removePrevMenu();
498 return;
499 }
500
cffd43cf 501 this.removePrevMenu();
52090a1f
CP
502 this.prevNick = e;
503 e.addClass("selected");
d8272bcb 504 this.moveMenuClass();
27add99a 505 e.menu = this.createMenu(e.realNick, e);
52090a1f
CP
506 new Event(x).stop();
507 }.bind(this));
52090a1f 508
fd60516d 509 e.addEvent("focus", function() { this.blur() }.bind(e));
d8272bcb 510 this.moveMenuClass();
52090a1f
CP
511 return e;
512 },
513 nickListRemove: function(nick, stored) {
514 this.nicklist.removeChild(stored);
d8272bcb 515 this.moveMenuClass();
f4ae92cc
CP
516 },
517 updateTopic: function(topic) {
f4ae92cc
CP
518 var t = this.topic;
519
520 while(t.firstChild)
521 t.removeChild(t.firstChild);
522
66de775f 523 if(topic) {
eaf3ed38 524 t.topicText = topic;
1f06a70a 525 this.parent(topic, t);
66de775f 526 } else {
eaf3ed38 527 t.topicText = topic;
359b7edd
CP
528 var e = new Element("div");
529 e.set("text", "(no topic set)");
66de775f 530 e.addClass("emptytopic");
359b7edd 531 t.appendChild(e);
66de775f 532 }
359b7edd 533 this.reflow();
f4ae92cc
CP
534 },
535 select: function() {
e20e5a6b 536 var inputVisible = this.type != qwebirc.ui.WINDOW_CONNECT && this.type != qwebirc.ui.WINDOW_CUSTOM;
6c19eb8f 537
f4ae92cc 538 this.tab.removeClass("tab-unselected");
f4ae92cc 539 this.tab.addClass("tab-selected");
359b7edd 540
6c19eb8f
CP
541 this.parentObject.setLines(this.lines);
542 this.parentObject.setChannelItems(this.nicklist, this.topic);
543 this.parentObject.qjsui.showInput(inputVisible);
544 this.parentObject.qjsui.showChannel($defined(this.nicklist));
545
546 this.reflow();
24ede2cb 547
7c633700 548 this.parent();
25be5960 549
6c19eb8f
CP
550 if(inputVisible)
551 this.parentObject.inputbox.focus();
f4ae92cc
CP
552 },
553 deselect: function() {
554 this.parent();
555
f4ae92cc
CP
556 this.tab.removeClass("tab-selected");
557 this.tab.addClass("tab-unselected");
558 },
559 close: function() {
560 this.parent();
561
f4ae92cc
CP
562 this.parentObject.tabs.removeChild(this.tab);
563 },
b35116e2 564 addLine: function(type, line, colourClass) {
f4ae92cc
CP
565 var e = new Element("div");
566
b35116e2
CP
567 if(colourClass) {
568 e.addClass(colourClass);
f4ae92cc
CP
569 } else if(this.lastcolour) {
570 e.addClass("linestyle1");
571 } else {
572 e.addClass("linestyle2");
573 }
f4ae92cc 574 this.lastcolour = !this.lastcolour;
35155ba7 575
b35116e2 576 this.parent(type, line, colourClass, e);
be0bd774
CP
577 },
578 setHilighted: function(state) {
2a802692 579 var laststate = this.hilighted;
96f28062 580
be0bd774 581 this.parent(state);
96f28062
CP
582
583 if(state == laststate)
584 return;
585
586 this.tab.removeClass("tab-hilight-activity");
587 this.tab.removeClass("tab-hilight-us");
588 this.tab.removeClass("tab-hilight-speech");
f4ae92cc 589
96f28062
CP
590 switch(this.hilighted) {
591 case qwebirc.ui.HILIGHT_US:
592 this.tab.addClass("tab-hilight-us");
593 break;
594 case qwebirc.ui.HILIGHT_SPEECH:
595 this.tab.addClass("tab-hilight-speech");
596 break;
597 case qwebirc.ui.HILIGHT_ACTIVITY:
598 this.tab.addClass("tab-hilight-activity");
599 break;
be0bd774 600 }
f4ae92cc
CP
601 }
602});