]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/frontends/qui.js
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
);
6 this.parentElement
= parentElement
;
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();
15 this.qjsui
.top
.addClass("outertabbar");
17 this.qjsui
.bottom
.addClass("input");
18 this.qjsui
.right
.addClass("nicklist");
19 this.qjsui
.topic
.addClass("topic");
20 this.qjsui
.middle
.addClass("lines");
22 this.outerTabs
= this.qjsui
.top
;
23 this.__createDropdown();
25 this.tabs
= new Element("div");
26 this.tabs
.addClass("tabbar");
27 this.outerTabs
.appendChild(this.tabs
);
28 this.origtopic
= this.topic
= this.qjsui
.topic
;
29 this.origlines
= this.lines
= this.qjsui
.middle
;
30 this.orignicklist
= this.nicklist
= this.qjsui
.right
;
32 this.input
= this.qjsui
.bottom
;
33 this.reflow
= this.qjsui
.reflow
.bind(this.qjsui
);
35 this.tabs
.addEvent("mousewheel", function(x
) {
36 var event
= new Event(x
);
41 } else if(event
.wheel
< 0) {
51 __createDropdown: function() {
52 var dropdownMenu
= new Element("div");
53 dropdownMenu
.addClass("dropdownmenu");
54 var surface
= new Element("div");
55 surface
.addClass("surface");
56 dropdownMenu
.hide = function(noRemove
) {
57 dropdownMenu
.setStyle("display", "none");
58 dropdownMenu
.visible
= false;
60 this.parentElement
.removeChild(surface
);
62 surface
.addEvent("click", function() {
66 dropdownMenu
.hide(true);
67 this.parentElement
.appendChild(dropdownMenu
);
69 this.UICommands
.forEach(function(x
) {
71 var fn
= this[x
[1] + "Window"].bind(this);
72 var e
= new Element("a");
73 e
.addEvent("click", function() {
78 dropdownMenu
.appendChild(e
);
81 var dropdown
= new Element("div");
82 dropdown
.addClass("dropdown-tab");
83 dropdown
.appendChild(new Element("img", {src: "images/favicon.png", title: "menu", alt: "menu"}));
84 dropdown
.setStyle("opacity", 1);
86 var dropdownEffect
= new Fx
.Tween(dropdown
, {duration: "long", property: "opacity", link: "chain"});
87 dropdownEffect
.start(0.25);
88 dropdownEffect
.start(1);
89 dropdownEffect
.start(0.33);
90 dropdownEffect
.start(1);
92 this.outerTabs
.appendChild(dropdown
);
93 dropdownMenu
.show = function(x
){
96 if(dropdownMenu
.visible
) {
100 this.parentElement
.appendChild(surface
);
102 var left = x.client.x;
103 var top = x.client.y;
106 var top
= this.tabs
.getSize().y
;
108 dropdownMenu
.setStyle("left", 0);
109 dropdownMenu
.setStyle("top", top
);
110 dropdownMenu
.setStyle("display", "inline-block");
111 dropdownMenu
.visible
= true;
113 dropdown
.addEvent("click", dropdownMenu
.show
);
115 var dropdownhint
= new Element("div");
116 dropdownhint
.addClass("dropdownhint");
117 dropdownhint
.set("text", "Click the icon for the main menu.");
119 new Fx
.Morph(dropdownhint
, {duration: "normal", transition: Fx
.Transitions
.Sine
.easeOut
}).start({left: [900, 5]});
121 var hider = function() {
122 new Fx
.Morph(dropdownhint
, {duration: "long"}).start({left: [5, -900]});
124 var hider2 = function() {
125 if(dropdownhint
.hidden
)
127 this.parentElement
.removeChild(dropdownhint
);
128 dropdownhint
.hidden
= 1;
132 document
.addEvent("mousedown", hider2
);
133 document
.addEvent("keypress", hider2
);
135 this.parentElement
.appendChild(dropdownhint
);
137 createInput: function() {
138 var form
= new Element("form");
139 this.input
.appendChild(form
);
140 form
.addClass("input");
142 var inputbox
= new Element("input");
143 form
.appendChild(inputbox
);
144 this.inputbox
= inputbox
;
146 form
.addEvent("submit", function(e
) {
149 if(inputbox
.value
== "")
152 this.resetTabComplete();
153 this.getActiveWindow().historyExec(inputbox
.value
);
157 inputbox
.addEvent("focus", this.resetTabComplete
.bind(this));
158 inputbox
.addEvent("mousedown", this.resetTabComplete
.bind(this));
160 inputbox
.addEvent("keydown", function(e
) {
162 var cvalue
= inputbox
.value
;
165 resultfn
= this.commandhistory
.upLine
;
166 } else if(e
.key
== "down") {
167 resultfn
= this.commandhistory
.downLine
;
168 } else if(e
.key
== "tab") {
170 this.tabComplete(inputbox
);
173 /* ideally alt and other keys wouldn't break this */
174 this.resetTabComplete();
178 this.resetTabComplete();
179 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
180 this.commandhistory
.addLine(cvalue
, true);
182 var result
= resultfn
.bind(this.commandhistory
)();
187 this.lastcvalue
= result
;
189 inputbox
.value
= result
;
190 qwebirc
.util
.setAtEnd(inputbox
);
193 setLines: function(lines
) {
194 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
195 this.qjsui
.middle
= this.lines
= lines
;
197 setChannelItems: function(nicklist
, topic
) {
198 if(!$defined(nicklist
)) {
199 nicklist
= this.orignicklist
;
200 topic
= this.origtopic
;
202 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
203 this.qjsui
.right
= this.nicklist
= nicklist
;
205 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
206 this.qjsui
.topic
= this.topic
= topic
;
210 qwebirc
.ui
.QUI
.JSUI
= new Class({
211 Implements: [Events
],
212 initialize: function(class_
, parent
, sizer
) {
213 this.parent
= parent
;
214 this.sizer
= $defined(sizer
)?sizer:parent
;
216 this.class_
= class_
;
219 this.reflowevent
= null;
221 window
.addEvent("resize", function() {
225 applyClasses: function(pos
, l
) {
226 l
.addClass("dynamicpanel");
227 l
.addClass(this.class_
);
229 if(pos
== "middle") {
230 l
.addClass("leftboundpanel");
231 } else if(pos
== "top") {
232 l
.addClass("topboundpanel");
233 l
.addClass("widepanel");
234 } else if(pos
== "topic") {
235 l
.addClass("widepanel");
236 } else if(pos
== "right") {
237 l
.addClass("rightboundpanel");
238 } else if(pos
== "bottom") {
239 l
.addClass("bottomboundpanel");
240 l
.addClass("widepanel");
244 var XE = function(pos
) {
245 var element
= new Element("div");
246 this.applyClasses(pos
, element
);
248 this.parent
.appendChild(element
);
252 this.top
= XE("top");
253 this.topic
= XE("topic");
254 this.middle
= XE("middle");
255 this.right
= XE("right");
256 this.bottom
= XE("bottom");
258 reflow: function(delay
) {
263 $clear(this.reflowevent
);
265 this.reflowevent
= this.__reflow
.delay(delay
, this);
267 __reflow: function() {
268 var bottom
= this.bottom
;
269 var middle
= this.middle
;
270 var right
= this.right
;
271 var topic
= this.topic
;
274 var topicsize
= topic
.getSize();
275 var topsize
= top
.getSize();
276 var rightsize
= right
.getSize();
277 var bottomsize
= bottom
.getSize();
278 var docsize
= this.sizer
.getSize();
280 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
281 var mwidth
= (docsize
.x
- rightsize
.x
);
283 topic
.setStyle("top", topsize
.y
+ "px");
285 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
287 middle
.setStyle("height", mheight
+ "px");
288 right
.setStyle("height", mheight
+ "px");
292 middle
.setStyle("width", mwidth
+ "px");
293 right
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
294 right
.setStyle("left", mwidth
+ "px");
296 bottom
.setStyle("top", (docsize
.y
- bottomsize
.y
) + "px");
297 this.fireEvent("reflow");
299 showChannel: function(state
) {
300 var display
= "none";
304 this.right
.setStyle("display", display
);
305 this.topic
.setStyle("display", display
);
307 showInput: function(state
) {
308 this.bottom
.isVisible
= state
;
309 this.bottom
.setStyle("display", state
?"block":"none");
313 qwebirc
.ui
.QUI
.Window
= new Class({
314 Extends: qwebirc
.ui
.Window
,
316 initialize: function(parentObject
, client
, type
, name
, identifier
) {
317 this.parent(parentObject
, client
, type
, name
, identifier
);
319 this.tab
= new Element("a", {"href": "#"});
320 this.tab
.addClass("tab");
321 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
323 parentObject
.tabs
.appendChild(this.tab
);
325 this.tab
.appendText(name
);
326 this.tab
.addEvent("click", function(e
) {
332 parentObject
.selectWindow(this);
335 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
336 var tabclose
= new Element("span");
337 tabclose
.set("text", "X");
338 tabclose
.addClass("tabclose");
339 var close = function(e
) {
345 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
346 this.client
.exec("/PART " + name
);
350 //parentObject.inputbox.focus();
353 tabclose
.addEvent("click", close
);
354 this.tab
.addEvent("mouseup", function(e
) {
357 if(Browser
.Engine
.trident
)
360 if(e
.event
.button
== button
)
364 this.tab
.appendChild(tabclose
);
367 this.lines
= new Element("div");
368 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
369 this.lines
.addClass("lines");
370 if(type
!= qwebirc
.ui
.WINDOW_CUSTOM
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
)
371 this.lines
.addClass("ircwindow");
373 this.lines
.addEvent("scroll", function() {
374 this.scrolleddown
= this.scrolledDown();
375 this.scrollpos
= this.getScrollParent().getScroll();
378 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
379 this.topic
= new Element("div");
380 this.topic
.addClass("topic");
381 this.topic
.addClass("tab-invisible");
382 this.topic
.set("html", " ");
383 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
385 this.prevNick
= null;
386 this.nicklist
= new Element("div");
387 this.nicklist
.addClass("nicklist");
388 this.nicklist
.addClass("tab-invisible");
389 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
390 this.parentObject
.qjsui
.applyClasses("nicklist", this.nicklist
);
393 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
394 this.updateTopic("");
400 this.parentObject
.reflow();
402 onResize: function() {
403 if(this.scrolleddown
) {
404 if(Browser
.Engine
.trident
) {
405 this.scrollToBottom
.delay(5, this);
407 this.scrollToBottom();
409 } else if($defined(this.scrollpos
)) {
410 if(Browser
.Engine
.trident
) {
411 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
413 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
417 createMenu: function(nick
, parent
) {
418 var e
= new Element("div");
419 parent
.appendChild(e
);
422 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
423 var e2
= new Element("a");
427 e2
.set("text", "- " + x
[0]);
429 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
430 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
[1]); }.bind(this));
434 menuClick: function(fn
) {
436 this.prevNick.removeChild(this.prevNick.menu);
437 this.prevNick.menu = null;
439 fn
.bind(this)(this.prevNick
.realNick
);
440 this.removePrevMenu();
442 moveMenuClass: function() {
445 if(this.nicklist
.firstChild
== this.prevNick
) {
446 this.prevNick
.removeClass("selected-middle");
448 this.prevNick
.addClass("selected-middle");
451 removePrevMenu: function() {
455 this.prevNick
.removeClass("selected");
456 this.prevNick
.removeClass("selected-middle");
457 if(this.prevNick
.menu
)
458 this.prevNick
.removeChild(this.prevNick
.menu
);
459 this.prevNick
= null;
461 nickListAdd: function(nick
, position
) {
462 var e
= new Element("a");
463 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
466 e
.appendChild(document
.createTextNode(nick
));
468 e
.realNick
= this.client
.stripPrefix(nick
);
470 e
.addEvent("click", function(x
) {
471 if(this.prevNick
== e
) {
472 this.removePrevMenu();
476 this.removePrevMenu();
478 e
.addClass("selected");
479 this.moveMenuClass();
480 e
.menu
= this.createMenu(x
.realNick
, e
);
483 e
.addEvent("dblclick", function(x
) {
485 this.client
.exec("/QUERY " + e
.realNick
);
488 e
.addEvent("focus", function() { this.blur() }.bind(e
));
489 this.moveMenuClass();
492 nickListRemove: function(nick
, stored
) {
493 this.nicklist
.removeChild(stored
);
494 this.moveMenuClass();
496 updateTopic: function(topic
) {
500 t
.removeChild(t
.firstChild
);
503 this.parent(topic
, t
);
505 var e
= new Element("div");
506 e
.set("text", "(no topic set)");
507 e
.addClass("emptytopic");
513 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
515 this.tab
.removeClass("tab-unselected");
516 this.tab
.addClass("tab-selected");
518 this.parentObject
.setLines(this.lines
);
519 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
520 this.parentObject
.qjsui
.showInput(inputVisible
);
521 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
));
528 this.parentObject
.inputbox
.focus();
530 deselect: function() {
533 this.tab
.removeClass("tab-selected");
534 this.tab
.addClass("tab-unselected");
539 this.parentObject
.tabs
.removeChild(this.tab
);
541 addLine: function(type
, line
, colourClass
) {
542 var e
= new Element("div");
545 e
.addClass(colourClass
);
546 } else if(this.lastcolour
) {
547 e
.addClass("linestyle1");
549 e
.addClass("linestyle2");
551 this.lastcolour
= !this.lastcolour
;
553 this.parent(type
, line
, colourClass
, e
);
555 setHilighted: function(state
) {
556 laststate
= this.hilighted
;
560 if(state
== laststate
)
563 this.tab
.removeClass("tab-hilight-activity");
564 this.tab
.removeClass("tab-hilight-us");
565 this.tab
.removeClass("tab-hilight-speech");
567 switch(this.hilighted
) {
568 case qwebirc
.ui
.HILIGHT_US:
569 this.tab
.addClass("tab-hilight-us");
571 case qwebirc
.ui
.HILIGHT_SPEECH:
572 this.tab
.addClass("tab-hilight-speech");
574 case qwebirc
.ui
.HILIGHT_ACTIVITY:
575 this.tab
.addClass("tab-hilight-activity");