]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/frontends/qui.js
1 qwebirc
.ui
.QUI
= new Class({
2 Extends: qwebirc
.ui
.RootUI
,
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) {
52 this.reflow
.delay(100); /* Konqueror fix */
54 /* HACK, in Chrome this should work immediately but doesn't */
55 this.__createDropdownHint
.delay(100, this);
57 __createDropdownMenu: function() {
58 var dropdownMenu
= new Element("span");
59 dropdownMenu
.addClass("dropdownmenu");
61 dropdownMenu
.hide = function() {
62 dropdownMenu
.setStyle("display", "none");
63 dropdownMenu
.visible
= false;
64 document
.removeEvent("mousedown", hideEvent
);
66 var hideEvent = function() { dropdownMenu
.hide(); };
69 this.parentElement
.appendChild(dropdownMenu
);
71 this.UICommands
.forEach(function(x
) {
73 var fn
= this[x
[1] + "Window"].bind(this);
74 var e
= new Element("a");
75 e
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
76 e
.addEvent("click", function() {
81 dropdownMenu
.appendChild(e
);
84 var dropdown
= new Element("div");
85 dropdown
.addClass("dropdown-tab");
86 dropdown
.appendChild(new Element("img", {src: "images/favicon.png", title: "menu", alt: "menu"}));
87 dropdown
.setStyle("opacity", 1);
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);
95 this.outerTabs
.appendChild(dropdown
);
96 dropdownMenu
.show = function(x
) {
100 if(dropdownMenu
.visible
) {
104 var top
= this.outerTabs
.getSize().y
;
106 dropdownMenu
.setStyle("left", 0);
107 dropdownMenu
.setStyle("top", top
-1); /* -1 == top border */
108 dropdownMenu
.setStyle("display", "inline-block");
109 dropdownMenu
.visible
= true;
111 document
.addEvent("mousedown", hideEvent
);
113 dropdown
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
114 dropdown
.addEvent("click", dropdownMenu
.show
);
116 __createDropdownHint: function() {
117 var dropdownhint
= new Element("div");
118 dropdownhint
.addClass("dropdownhint");
119 dropdownhint
.set("text", "Click the icon for the main menu.");
120 dropdownhint
.setStyle("top", this.outerTabs
.getSize().y
+ 5);
122 this.parentElement
.appendChild(dropdownhint
);
123 new Fx
.Morph(dropdownhint
, {duration: "normal", transition: Fx
.Transitions
.Sine
.easeOut
}).start({left: [900, 5]});
125 var hider = function() {
126 new Fx
.Morph(dropdownhint
, {duration: "long"}).start({left: [5, -900]});
129 var hider2 = function() {
130 if(dropdownhint
.hidden
)
132 this.parentElement
.removeChild(dropdownhint
);
133 dropdownhint
.hidden
= 1;
136 this.hideHint
= hider2
;
138 document
.addEvent("mousedown", hider2
);
139 document
.addEvent("keypress", hider2
);
141 createInput: function() {
142 var form
= new Element("form");
143 this.input
.appendChild(form
);
145 form
.addClass("input");
147 var inputbox
= new Element("input");
148 form
.appendChild(inputbox
);
149 this.inputbox
= inputbox
;
150 this.inputbox
.maxLength
= 512;
152 var sendInput = function() {
153 if(inputbox
.value
== "")
156 this.resetTabComplete();
157 this.getActiveWindow().historyExec(inputbox
.value
);
161 if(!qwebirc
.util
.deviceHasKeyboard()) {
162 inputbox
.addClass("mobile-input");
163 var inputButton
= new Element("input", {type: "button"});
164 inputButton
.addClass("mobile-button");
165 inputButton
.addEvent("click", function() {
169 inputButton
.value
= ">";
170 this.input
.appendChild(inputButton
);
171 var reflowButton = function() {
172 var containerSize
= this.input
.getSize();
173 var buttonSize
= inputButton
.getSize();
175 var buttonLeft
= containerSize
.x
- buttonSize
.x
- 5; /* lovely 5 */
177 inputButton
.setStyle("left", buttonLeft
);
178 inputbox
.setStyle("width", buttonLeft
- 5);
179 inputButton
.setStyle("height", containerSize
.y
);
181 this.qjsui
.addEvent("reflow", reflowButton
);
183 inputbox
.addClass("keyboard-input");
186 form
.addEvent("submit", function(e
) {
191 inputbox
.addEvent("focus", this.resetTabComplete
.bind(this));
192 inputbox
.addEvent("mousedown", this.resetTabComplete
.bind(this));
194 inputbox
.addEvent("keydown", function(e
) {
196 var cvalue
= inputbox
.value
;
199 resultfn
= this.commandhistory
.upLine
;
200 } else if(e
.key
== "down") {
201 resultfn
= this.commandhistory
.downLine
;
202 } else if(e
.key
== "tab") {
204 this.tabComplete(inputbox
);
207 /* ideally alt and other keys wouldn't break this */
208 this.resetTabComplete();
212 this.resetTabComplete();
213 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
214 this.commandhistory
.addLine(cvalue
, true);
216 var result
= resultfn
.bind(this.commandhistory
)();
221 this.lastcvalue
= result
;
223 inputbox
.value
= result
;
224 qwebirc
.util
.setAtEnd(inputbox
);
227 setLines: function(lines
) {
228 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
229 this.qjsui
.middle
= this.lines
= lines
;
231 setChannelItems: function(nicklist
, topic
) {
232 if(!$defined(nicklist
)) {
233 nicklist
= this.orignicklist
;
234 topic
= this.origtopic
;
236 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
237 this.qjsui
.right
= this.nicklist
= nicklist
;
239 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
240 this.qjsui
.topic
= this.topic
= topic
;
244 qwebirc
.ui
.QUI
.JSUI
= new Class({
245 Implements: [Events
],
246 initialize: function(class_
, parent
, sizer
) {
247 this.parent
= parent
;
248 this.sizer
= $defined(sizer
)?sizer:parent
;
250 this.class_
= class_
;
253 this.reflowevent
= null;
255 window
.addEvent("resize", function() {
259 applyClasses: function(pos
, l
) {
260 l
.addClass("dynamicpanel");
261 l
.addClass(this.class_
);
263 if(pos
== "middle") {
264 l
.addClass("leftboundpanel");
265 } else if(pos
== "top") {
266 l
.addClass("topboundpanel");
267 l
.addClass("widepanel");
268 } else if(pos
== "topic") {
269 l
.addClass("widepanel");
270 } else if(pos
== "right") {
271 l
.addClass("rightboundpanel");
272 } else if(pos
== "bottom") {
273 l
.addClass("bottomboundpanel");
274 l
.addClass("widepanel");
278 var XE = function(pos
) {
279 var element
= new Element("div");
280 this.applyClasses(pos
, element
);
282 this.parent
.appendChild(element
);
286 this.top
= XE("top");
287 this.topic
= XE("topic");
288 this.middle
= XE("middle");
289 this.right
= XE("right");
290 this.bottom
= XE("bottom");
292 reflow: function(delay
) {
297 $clear(this.reflowevent
);
299 this.reflowevent
= this.__reflow
.delay(delay
, this);
301 __reflow: function() {
302 var bottom
= this.bottom
;
303 var middle
= this.middle
;
304 var right
= this.right
;
305 var topic
= this.topic
;
308 var topicsize
= topic
.getSize();
309 var topsize
= top
.getSize();
310 var rightsize
= right
.getSize();
311 var bottomsize
= bottom
.getSize();
312 var docsize
= this.sizer
.getSize();
314 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
315 var mwidth
= (docsize
.x
- rightsize
.x
);
317 topic
.setStyle("top", topsize
.y
);
319 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
));
321 middle
.setStyle("height", mheight
);
322 right
.setStyle("height", mheight
);
326 middle
.setStyle("width", mwidth
);
327 right
.setStyle("top", (topsize
.y
+ topicsize
.y
));
328 right
.setStyle("left", mwidth
);
330 bottom
.setStyle("top", (docsize
.y
- bottomsize
.y
));
331 this.fireEvent("reflow");
333 showChannel: function(state
) {
334 var display
= "none";
338 this.right
.setStyle("display", display
);
339 this.topic
.setStyle("display", display
);
341 showInput: function(state
) {
342 this.bottom
.isVisible
= state
;
343 this.bottom
.setStyle("display", state
?"block":"none");
347 qwebirc
.ui
.QUI
.Window
= new Class({
348 Extends: qwebirc
.ui
.Window
,
350 initialize: function(parentObject
, client
, type
, name
, identifier
) {
351 this.parent(parentObject
, client
, type
, name
, identifier
);
353 this.tab
= new Element("a", {"href": "#"});
354 this.tab
.addClass("tab");
355 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
357 parentObject
.tabs
.appendChild(this.tab
);
359 this.tab
.appendText(name
);
360 this.tab
.addEvent("click", function(e
) {
366 parentObject
.selectWindow(this);
369 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
370 var tabclose
= new Element("span");
371 tabclose
.set("text", "X");
372 tabclose
.addClass("tabclose");
373 var close = function(e
) {
379 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
380 this.client
.exec("/PART " + name
);
384 //parentObject.inputbox.focus();
387 tabclose
.addEvent("click", close
);
388 this.tab
.addEvent("mouseup", function(e
) {
391 if(Browser
.Engine
.trident
)
394 if(e
.event
.button
== button
)
398 this.tab
.appendChild(tabclose
);
401 this.lines
= new Element("div");
402 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
403 this.lines
.addClass("lines");
404 if(type
!= qwebirc
.ui
.WINDOW_CUSTOM
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
)
405 this.lines
.addClass("ircwindow");
407 this.lines
.addEvent("scroll", function() {
408 this.scrolleddown
= this.scrolledDown();
409 this.scrollpos
= this.getScrollParent().getScroll();
412 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
413 this.topic
= new Element("div");
414 this.topic
.addClass("topic");
415 this.topic
.addClass("tab-invisible");
416 this.topic
.set("html", " ");
417 this.topic
.addEvent("click", this.editTopic
.bind(this));
418 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
420 this.prevNick
= null;
421 this.nicklist
= new Element("div");
422 this.nicklist
.addClass("nicklist");
423 this.nicklist
.addClass("tab-invisible");
424 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
425 this.parentObject
.qjsui
.applyClasses("nicklist", this.nicklist
);
428 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
429 this.updateTopic("");
434 editTopic: function() {
435 if(!this.client
.nickOnChanHasPrefix(this.client
.nickname
, this.name
, "@")) {
436 /* var cmodes = this.client.getChannelModes(channel);
437 if(cmodes.indexOf("t")) {*/
438 alert("Sorry, you need to be opped to change the topic!");
442 var newTopic
= prompt("Change topic of " + this.name
+ " to:", this.topic
.topicText
);
443 if(newTopic
=== null)
446 this.client
.exec("/TOPIC " + newTopic
);
449 this.parentObject
.reflow();
451 onResize: function() {
452 if(this.scrolleddown
) {
453 if(Browser
.Engine
.trident
) {
454 this.scrollToBottom
.delay(5, this);
456 this.scrollToBottom();
458 } else if($defined(this.scrollpos
)) {
459 if(Browser
.Engine
.trident
) {
460 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
462 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
466 createMenu: function(nick
, parent
) {
467 var e
= new Element("div");
468 parent
.appendChild(e
);
471 var nickArray
= [nick
];
472 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
473 if(!x
.predicate
|| x
.predicate
!== true && !x
.predicate
.apply(this, nickArray
))
476 var e2
= new Element("a");
480 e2
.set("text", "- " + x
.text
);
482 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
483 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
.fn
); }.bind(this));
487 menuClick: function(fn
) {
489 this.prevNick.removeChild(this.prevNick.menu);
490 this.prevNick.menu = null;
492 fn
.bind(this)(this.prevNick
.realNick
);
493 this.removePrevMenu();
495 moveMenuClass: function() {
498 if(this.nicklist
.firstChild
== this.prevNick
) {
499 this.prevNick
.removeClass("selected-middle");
501 this.prevNick
.addClass("selected-middle");
504 removePrevMenu: function() {
508 this.prevNick
.removeClass("selected");
509 this.prevNick
.removeClass("selected-middle");
510 if(this.prevNick
.menu
)
511 this.prevNick
.removeChild(this.prevNick
.menu
);
512 this.prevNick
= null;
514 nickListAdd: function(nick
, position
) {
515 var e
= new Element("a");
516 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
519 e
.appendChild(document
.createTextNode(nick
));
521 e
.realNick
= this.client
.stripPrefix(nick
);
523 e
.addEvent("click", function(x
) {
524 if(this.prevNick
== e
) {
525 this.removePrevMenu();
529 this.removePrevMenu();
531 e
.addClass("selected");
532 this.moveMenuClass();
533 e
.menu
= this.createMenu(e
.realNick
, e
);
537 e
.addEvent("focus", function() { this.blur() }.bind(e
));
538 this.moveMenuClass();
541 nickListRemove: function(nick
, stored
) {
542 this.nicklist
.removeChild(stored
);
543 this.moveMenuClass();
545 updateTopic: function(topic
) {
549 t
.removeChild(t
.firstChild
);
553 this.parent(topic
, t
);
556 var e
= new Element("div");
557 e
.set("text", "(no topic set)");
558 e
.addClass("emptytopic");
564 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
566 this.tab
.removeClass("tab-unselected");
567 this.tab
.addClass("tab-selected");
569 this.parentObject
.setLines(this.lines
);
570 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
571 this.parentObject
.qjsui
.showInput(inputVisible
);
572 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
));
579 this.parentObject
.inputbox
.focus();
581 deselect: function() {
584 this.tab
.removeClass("tab-selected");
585 this.tab
.addClass("tab-unselected");
590 this.parentObject
.tabs
.removeChild(this.tab
);
592 addLine: function(type
, line
, colourClass
) {
593 var e
= new Element("div");
596 e
.addClass(colourClass
);
597 } else if(this.lastcolour
) {
598 e
.addClass("linestyle1");
600 e
.addClass("linestyle2");
602 this.lastcolour
= !this.lastcolour
;
604 this.parent(type
, line
, colourClass
, e
);
606 setHilighted: function(state
) {
607 var laststate
= this.hilighted
;
611 if(state
== laststate
)
614 this.tab
.removeClass("tab-hilight-activity");
615 this.tab
.removeClass("tab-hilight-us");
616 this.tab
.removeClass("tab-hilight-speech");
618 switch(this.hilighted
) {
619 case qwebirc
.ui
.HILIGHT_US:
620 this.tab
.addClass("tab-hilight-us");
622 case qwebirc
.ui
.HILIGHT_SPEECH:
623 this.tab
.addClass("tab-hilight-speech");
625 case qwebirc
.ui
.HILIGHT_ACTIVITY:
626 this.tab
.addClass("tab-hilight-activity");