]>
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
;
24 this.tabs
= new Element("div");
25 this.tabs
.addClass("tabbar");
27 this.__createDropdownMenu();
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
;
34 this.input
= this.qjsui
.bottom
;
35 this.reflow
= this.qjsui
.reflow
.bind(this.qjsui
);
37 this.tabs
.addEvent("mousewheel", function(x
) {
38 var event
= new Event(x
);
43 } else if(event
.wheel
< 0) {
53 /* HACK, in Chrome this should work immediately but doesn't */
54 this.__createDropdownHint
.delay(100, this);
56 __createDropdownMenu: function() {
57 var dropdownMenu
= new Element("span");
58 dropdownMenu
.addClass("dropdownmenu");
60 dropdownMenu
.hide = function() {
61 dropdownMenu
.setStyle("display", "none");
62 dropdownMenu
.visible
= false;
63 document
.removeEvent("mousedown", hideEvent
);
65 var hideEvent = function() { dropdownMenu
.hide(); };
68 this.parentElement
.appendChild(dropdownMenu
);
70 this.UICommands
.forEach(function(x
) {
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() {
80 dropdownMenu
.appendChild(e
);
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);
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);
94 this.outerTabs
.appendChild(dropdown
);
95 dropdownMenu
.show = function(x
) {
99 if(dropdownMenu
.visible
) {
103 var top
= this.outerTabs
.getSize().y
;
105 dropdownMenu
.setStyle("left", 0);
106 dropdownMenu
.setStyle("top", top
-1); /* -1 == top border */
107 dropdownMenu
.setStyle("display", "inline-block");
108 dropdownMenu
.visible
= true;
110 document
.addEvent("mousedown", hideEvent
);
112 dropdown
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
113 dropdown
.addEvent("click", dropdownMenu
.show
);
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);
121 this.parentElement
.appendChild(dropdownhint
);
122 new Fx
.Morph(dropdownhint
, {duration: "normal", transition: Fx
.Transitions
.Sine
.easeOut
}).start({left: [900, 5]});
124 var hider = function() {
125 new Fx
.Morph(dropdownhint
, {duration: "long"}).start({left: [5, -900]});
128 var hider2 = function() {
129 if(dropdownhint
.hidden
)
131 this.parentElement
.removeChild(dropdownhint
);
132 dropdownhint
.hidden
= 1;
135 this.hideHint
= hider2
;
137 document
.addEvent("mousedown", hider2
);
138 document
.addEvent("keypress", hider2
);
141 createInput: function() {
142 var form
= new Element("form");
143 this.input
.appendChild(form
);
144 form
.addClass("input");
146 var inputbox
= new Element("input");
147 form
.appendChild(inputbox
);
148 this.inputbox
= inputbox
;
150 form
.addEvent("submit", function(e
) {
153 if(inputbox
.value
== "")
156 this.resetTabComplete();
157 this.getActiveWindow().historyExec(inputbox
.value
);
161 inputbox
.addEvent("focus", this.resetTabComplete
.bind(this));
162 inputbox
.addEvent("mousedown", this.resetTabComplete
.bind(this));
164 inputbox
.addEvent("keydown", function(e
) {
166 var cvalue
= inputbox
.value
;
169 resultfn
= this.commandhistory
.upLine
;
170 } else if(e
.key
== "down") {
171 resultfn
= this.commandhistory
.downLine
;
172 } else if(e
.key
== "tab") {
174 this.tabComplete(inputbox
);
177 /* ideally alt and other keys wouldn't break this */
178 this.resetTabComplete();
182 this.resetTabComplete();
183 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
184 this.commandhistory
.addLine(cvalue
, true);
186 var result
= resultfn
.bind(this.commandhistory
)();
191 this.lastcvalue
= result
;
193 inputbox
.value
= result
;
194 qwebirc
.util
.setAtEnd(inputbox
);
197 setLines: function(lines
) {
198 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
199 this.qjsui
.middle
= this.lines
= lines
;
201 setChannelItems: function(nicklist
, topic
) {
202 if(!$defined(nicklist
)) {
203 nicklist
= this.orignicklist
;
204 topic
= this.origtopic
;
206 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
207 this.qjsui
.right
= this.nicklist
= nicklist
;
209 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
210 this.qjsui
.topic
= this.topic
= topic
;
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
;
220 this.class_
= class_
;
223 this.reflowevent
= null;
225 window
.addEvent("resize", function() {
229 applyClasses: function(pos
, l
) {
230 l
.addClass("dynamicpanel");
231 l
.addClass(this.class_
);
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");
248 var XE = function(pos
) {
249 var element
= new Element("div");
250 this.applyClasses(pos
, element
);
252 this.parent
.appendChild(element
);
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");
262 reflow: function(delay
) {
267 $clear(this.reflowevent
);
269 this.reflowevent
= this.__reflow
.delay(delay
, this);
271 __reflow: function() {
272 var bottom
= this.bottom
;
273 var middle
= this.middle
;
274 var right
= this.right
;
275 var topic
= this.topic
;
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();
284 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
285 var mwidth
= (docsize
.x
- rightsize
.x
);
287 topic
.setStyle("top", topsize
.y
);
289 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
));
291 middle
.setStyle("height", mheight
);
292 right
.setStyle("height", mheight
);
296 middle
.setStyle("width", mwidth
);
297 right
.setStyle("top", (topsize
.y
+ topicsize
.y
));
298 right
.setStyle("left", mwidth
);
300 bottom
.setStyle("top", (docsize
.y
- bottomsize
.y
));
301 this.fireEvent("reflow");
303 showChannel: function(state
) {
304 var display
= "none";
308 this.right
.setStyle("display", display
);
309 this.topic
.setStyle("display", display
);
311 showInput: function(state
) {
312 this.bottom
.isVisible
= state
;
313 this.bottom
.setStyle("display", state
?"block":"none");
317 qwebirc
.ui
.QUI
.Window
= new Class({
318 Extends: qwebirc
.ui
.Window
,
320 initialize: function(parentObject
, client
, type
, name
, identifier
) {
321 this.parent(parentObject
, client
, type
, name
, identifier
);
323 this.tab
= new Element("a", {"href": "#"});
324 this.tab
.addClass("tab");
325 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
327 parentObject
.tabs
.appendChild(this.tab
);
329 this.tab
.appendText(name
);
330 this.tab
.addEvent("click", function(e
) {
336 parentObject
.selectWindow(this);
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
) {
349 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
350 this.client
.exec("/PART " + name
);
354 //parentObject.inputbox.focus();
357 tabclose
.addEvent("click", close
);
358 this.tab
.addEvent("mouseup", function(e
) {
361 if(Browser
.Engine
.trident
)
364 if(e
.event
.button
== button
)
368 this.tab
.appendChild(tabclose
);
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");
377 this.lines
.addEvent("scroll", function() {
378 this.scrolleddown
= this.scrolledDown();
379 this.scrollpos
= this.getScrollParent().getScroll();
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
);
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
);
397 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
398 this.updateTopic("");
404 this.parentObject
.reflow();
406 onResize: function() {
407 if(this.scrolleddown
) {
408 if(Browser
.Engine
.trident
) {
409 this.scrollToBottom
.delay(5, this);
411 this.scrollToBottom();
413 } else if($defined(this.scrollpos
)) {
414 if(Browser
.Engine
.trident
) {
415 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
417 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
421 createMenu: function(nick
, parent
) {
422 var e
= new Element("div");
423 parent
.appendChild(e
);
426 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
427 var e2
= new Element("a");
431 e2
.set("text", "- " + x
[0]);
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));
438 menuClick: function(fn
) {
440 this.prevNick.removeChild(this.prevNick.menu);
441 this.prevNick.menu = null;
443 fn
.bind(this)(this.prevNick
.realNick
);
444 this.removePrevMenu();
446 moveMenuClass: function() {
449 if(this.nicklist
.firstChild
== this.prevNick
) {
450 this.prevNick
.removeClass("selected-middle");
452 this.prevNick
.addClass("selected-middle");
455 removePrevMenu: function() {
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;
465 nickListAdd: function(nick
, position
) {
466 var e
= new Element("a");
467 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
470 e
.appendChild(document
.createTextNode(nick
));
472 e
.realNick
= this.client
.stripPrefix(nick
);
474 e
.addEvent("click", function(x
) {
475 if(this.prevNick
== e
) {
476 this.removePrevMenu();
480 this.removePrevMenu();
482 e
.addClass("selected");
483 this.moveMenuClass();
484 e
.menu
= this.createMenu(x
.realNick
, e
);
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");