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