]>
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
;
7 this.setModifiableStylesheet("qui");
9 postInitialize: function() {
10 this.qjsui
= new qwebirc
.ui
.QUI
.JSUI("qwebirc-qui", this.parentElement
);
11 this.qjsui
.addEvent("reflow", function() {
12 var w
= this.getActiveWindow();
16 this.qjsui
.top
.addClass("outertabbar");
18 this.qjsui
.bottom
.addClass("input");
19 this.qjsui
.right
.addClass("nicklist");
20 this.qjsui
.topic
.addClass("topic");
21 this.qjsui
.middle
.addClass("lines");
23 this.outerTabs
= this.qjsui
.top
;
25 this.tabs
= new Element("div");
26 this.tabs
.addClass("tabbar");
28 this.__createDropdownMenu();
30 this.outerTabs
.appendChild(this.tabs
);
31 this.origtopic
= this.topic
= this.qjsui
.topic
;
32 this.origlines
= this.lines
= this.qjsui
.middle
;
33 this.orignicklist
= this.nicklist
= this.qjsui
.right
;
35 this.input
= this.qjsui
.bottom
;
36 this.reflow
= this.qjsui
.reflow
.bind(this.qjsui
);
38 this.tabs
.addEvent("mousewheel", function(x
) {
39 var event
= new Event(x
);
44 } else if(event
.wheel
< 0) {
53 this.reflow
.delay(100); /* Konqueror fix */
55 /* HACK, in Chrome this should work immediately but doesn't */
56 this.__createDropdownHint
.delay(100, this);
58 __createDropdownMenu: function() {
59 var dropdownMenu
= new Element("span");
60 dropdownMenu
.addClass("dropdownmenu");
62 dropdownMenu
.hide = function() {
63 dropdownMenu
.setStyle("display", "none");
64 dropdownMenu
.visible
= false;
65 document
.removeEvent("mousedown", hideEvent
);
67 var hideEvent = function() { dropdownMenu
.hide(); };
70 this.parentElement
.appendChild(dropdownMenu
);
72 this.UICommands
.forEach(function(x
) {
74 var fn
= this[x
[1] + "Window"].bind(this);
75 var e
= new Element("a");
76 e
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
77 e
.addEvent("click", function() {
82 dropdownMenu
.appendChild(e
);
85 var dropdown
= new Element("div");
86 dropdown
.addClass("dropdown-tab");
87 dropdown
.appendChild(new Element("img", {src: qwebirc
.global
.staticBaseURL
+ "images/icon.png", title: "menu", alt: "menu"}));
88 dropdown
.setStyle("opacity", 1);
90 var dropdownEffect
= new Fx
.Tween(dropdown
, {duration: "long", property: "opacity", link: "chain"});
91 dropdownEffect
.start(0.25);
92 dropdownEffect
.start(1);
93 dropdownEffect
.start(0.33);
94 dropdownEffect
.start(1);
96 this.outerTabs
.appendChild(dropdown
);
97 dropdownMenu
.show = function(x
) {
101 if(dropdownMenu
.visible
) {
105 var top
= this.outerTabs
.getSize().y
;
107 dropdownMenu
.setStyle("left", 0);
108 dropdownMenu
.setStyle("top", top
-1); /* -1 == top border */
109 dropdownMenu
.setStyle("display", "inline-block");
110 dropdownMenu
.visible
= true;
112 document
.addEvent("mousedown", hideEvent
);
114 dropdown
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
115 dropdown
.addEvent("click", dropdownMenu
.show
);
117 __createDropdownHint: function() {
118 var dropdownhint
= new Element("div");
119 dropdownhint
.addClass("dropdownhint");
120 dropdownhint
.set("text", "Click the icon for the main menu.");
121 dropdownhint
.setStyle("top", this.outerTabs
.getSize().y
+ 5);
123 this.parentElement
.appendChild(dropdownhint
);
124 new Fx
.Morph(dropdownhint
, {duration: "normal", transition: Fx
.Transitions
.Sine
.easeOut
}).start({left: [900, 5]});
126 var hider = function() {
127 new Fx
.Morph(dropdownhint
, {duration: "long"}).start({left: [5, -900]});
130 var hider2 = function() {
131 if(dropdownhint
.hidden
)
133 this.parentElement
.removeChild(dropdownhint
);
134 dropdownhint
.hidden
= 1;
137 this.hideHint
= hider2
;
139 document
.addEvent("mousedown", hider2
);
140 document
.addEvent("keypress", hider2
);
142 createInput: function() {
143 var form
= new Element("form");
144 this.input
.appendChild(form
);
146 form
.addClass("input");
148 var inputbox
= new Element("input");
149 form
.appendChild(inputbox
);
150 this.inputbox
= inputbox
;
151 this.inputbox
.maxLength
= 470;
153 var sendInput = function() {
154 if(inputbox
.value
== "")
157 this.resetTabComplete();
158 this.getActiveWindow().historyExec(inputbox
.value
);
162 if(!qwebirc
.util
.deviceHasKeyboard()) {
163 inputbox
.addClass("mobile-input");
164 var inputButton
= new Element("input", {type: "button"});
165 inputButton
.addClass("mobile-button");
166 inputButton
.addEvent("click", function() {
170 inputButton
.value
= ">";
171 this.input
.appendChild(inputButton
);
172 var reflowButton = function() {
173 var containerSize
= this.input
.getSize();
174 var buttonSize
= inputButton
.getSize();
176 var buttonLeft
= containerSize
.x
- buttonSize
.x
- 5; /* lovely 5 */
178 inputButton
.setStyle("left", buttonLeft
);
179 inputbox
.setStyle("width", buttonLeft
- 5);
180 inputButton
.setStyle("height", containerSize
.y
);
182 this.qjsui
.addEvent("reflow", reflowButton
);
184 inputbox
.addClass("keyboard-input");
187 form
.addEvent("submit", function(e
) {
192 inputbox
.addEvent("focus", this.resetTabComplete
.bind(this));
193 inputbox
.addEvent("mousedown", this.resetTabComplete
.bind(this));
195 inputbox
.addEvent("keydown", function(e
) {
197 var cvalue
= inputbox
.value
;
200 resultfn
= this.commandhistory
.upLine
;
201 } else if(e
.key
== "down") {
202 resultfn
= this.commandhistory
.downLine
;
203 } else if(e
.key
== "tab") {
205 this.tabComplete(inputbox
);
208 /* ideally alt and other keys wouldn't break this */
209 this.resetTabComplete();
213 this.resetTabComplete();
214 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
215 this.commandhistory
.addLine(cvalue
, true);
217 var result
= resultfn
.bind(this.commandhistory
)();
222 this.lastcvalue
= result
;
224 inputbox
.value
= result
;
225 qwebirc
.util
.setAtEnd(inputbox
);
228 setLines: function(lines
) {
229 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
230 this.qjsui
.middle
= this.lines
= lines
;
232 setChannelItems: function(nicklist
, topic
) {
233 if(!$defined(nicklist
)) {
234 nicklist
= this.orignicklist
;
235 topic
= this.origtopic
;
237 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
238 this.qjsui
.right
= this.nicklist
= nicklist
;
240 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
241 this.qjsui
.topic
= this.topic
= topic
;
245 qwebirc
.ui
.QUI
.JSUI
= new Class({
246 Implements: [Events
],
247 initialize: function(class_
, parent
, sizer
) {
248 this.parent
= parent
;
249 this.sizer
= $defined(sizer
)?sizer:parent
;
251 this.class_
= class_
;
254 this.reflowevent
= null;
256 window
.addEvent("resize", function() {
260 applyClasses: function(pos
, l
) {
261 l
.addClass("dynamicpanel");
262 l
.addClass(this.class_
);
264 if(pos
== "middle") {
265 l
.addClass("leftboundpanel");
266 } else if(pos
== "top") {
267 l
.addClass("topboundpanel");
268 l
.addClass("widepanel");
269 } else if(pos
== "topic") {
270 l
.addClass("widepanel");
271 } else if(pos
== "right") {
272 l
.addClass("rightboundpanel");
273 } else if(pos
== "bottom") {
274 l
.addClass("bottomboundpanel");
275 l
.addClass("widepanel");
279 var XE = function(pos
) {
280 var element
= new Element("div");
281 this.applyClasses(pos
, element
);
283 this.parent
.appendChild(element
);
287 this.top
= XE("top");
288 this.topic
= XE("topic");
289 this.middle
= XE("middle");
290 this.right
= XE("right");
291 this.bottom
= XE("bottom");
293 reflow: function(delay
) {
298 $clear(this.reflowevent
);
300 this.reflowevent
= this.__reflow
.delay(delay
, this);
302 __reflow: function() {
303 var bottom
= this.bottom
;
304 var middle
= this.middle
;
305 var right
= this.right
;
306 var topic
= this.topic
;
309 var topicsize
= topic
.getSize();
310 var topsize
= top
.getSize();
311 var rightsize
= right
.getSize();
312 var bottomsize
= bottom
.getSize();
313 var docsize
= this.sizer
.getSize();
315 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
316 var mwidth
= (docsize
.x
- rightsize
.x
);
318 topic
.setStyle("top", topsize
.y
);
320 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
));
322 middle
.setStyle("height", mheight
);
323 right
.setStyle("height", mheight
);
327 middle
.setStyle("width", mwidth
);
328 right
.setStyle("top", (topsize
.y
+ topicsize
.y
));
329 right
.setStyle("left", mwidth
);
331 bottom
.setStyle("top", (docsize
.y
- bottomsize
.y
));
332 this.fireEvent("reflow");
334 showChannel: function(state
, nicklistVisible
) {
335 var display
= "none";
339 this.right
.setStyle("display", nicklistVisible
? display : "none");
340 this.topic
.setStyle("display", display
);
342 showInput: function(state
) {
343 this.bottom
.isVisible
= state
;
344 this.bottom
.setStyle("display", state
?"block":"none");
348 qwebirc
.ui
.QUI
.Window
= new Class({
349 Extends: qwebirc
.ui
.Window
,
351 initialize: function(parentObject
, client
, type
, name
, identifier
) {
352 this.parent(parentObject
, client
, type
, name
, identifier
);
354 this.tab
= new Element("a", {"href": "#"});
355 this.tab
.addClass("tab");
356 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
358 this.spaceNode
= document
.createTextNode(" ");
359 parentObject
.tabs
.appendChild(this.tab
);
360 parentObject
.tabs
.appendChild(this.spaceNode
);
362 this.tab
.appendText(name
);
363 this.tab
.addEvent("click", function(e
) {
369 parentObject
.selectWindow(this);
372 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
373 var tabclose
= new Element("span");
374 tabclose
.set("text", "X");
375 tabclose
.addClass("tabclose");
376 var close = function(e
) {
382 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
383 this.client
.exec("/PART " + name
);
387 //parentObject.inputbox.focus();
390 tabclose
.addEvent("click", close
);
391 this.tab
.addEvent("mouseup", function(e
) {
394 if(Browser
.Engine
.trident
)
397 if(e
.event
.button
== button
)
401 this.tab
.appendChild(tabclose
);
404 this.lines
= new Element("div");
405 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
406 this.lines
.addClass("lines");
407 if(type
!= qwebirc
.ui
.WINDOW_CUSTOM
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
)
408 this.lines
.addClass("ircwindow");
410 this.lines
.addEvent("scroll", function() {
411 this.scrolleddown
= this.scrolledDown();
412 this.scrollpos
= this.getScrollParent().getScroll();
415 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
416 this.topic
= new Element("div");
417 this.topic
.addClass("topic");
418 this.topic
.addClass("tab-invisible");
419 this.topic
.set("html", " ");
420 this.topic
.addEvent("dblclick", this.editTopic
.bind(this));
421 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
423 this.prevNick
= null;
424 this.nicklist
= new Element("div");
425 this.nicklist
.addClass("nicklist");
426 this.nicklist
.addClass("tab-invisible");
427 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
428 this.parentObject
.qjsui
.applyClasses("nicklist", this.nicklist
);
431 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
432 this.updateTopic("");
434 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
437 editTopic: function() {
438 if(!this.client
.nickOnChanHasPrefix(this.client
.nickname
, this.name
, "@")) {
439 /* var cmodes = this.client.getChannelModes(channel);
440 if(cmodes.indexOf("t")) {*/
441 alert("Sorry, you need to be a channel operator to change the topic!");
445 var newTopic
= prompt("Change topic of " + this.name
+ " to:", this.topic
.topicText
);
446 if(newTopic
=== null)
449 this.client
.exec("/TOPIC " + newTopic
);
452 this.parentObject
.reflow();
454 onResize: function() {
455 if(this.scrolleddown
) {
456 if(Browser
.Engine
.trident
) {
457 this.scrollToBottom
.delay(5, this);
459 this.scrollToBottom();
461 } else if($defined(this.scrollpos
)) {
462 if(Browser
.Engine
.trident
) {
463 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
465 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
469 createMenu: function(nick
, parent
) {
470 var e
= new Element("div");
471 parent
.appendChild(e
);
474 var nickArray
= [nick
];
475 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
476 if(!x
.predicate
|| x
.predicate
!== true && !x
.predicate
.apply(this, nickArray
))
479 var e2
= new Element("a");
483 e2
.set("text", "- " + x
.text
);
485 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
486 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
.fn
); }.bind(this));
490 menuClick: function(fn
) {
492 this.prevNick.removeChild(this.prevNick.menu);
493 this.prevNick.menu = null;
495 fn
.bind(this)(this.prevNick
.realNick
);
496 this.removePrevMenu();
498 moveMenuClass: function() {
501 if(this.nicklist
.firstChild
== this.prevNick
) {
502 this.prevNick
.removeClass("selected-middle");
504 this.prevNick
.addClass("selected-middle");
507 removePrevMenu: function() {
511 this.prevNick
.removeClass("selected");
512 this.prevNick
.removeClass("selected-middle");
513 if(this.prevNick
.menu
)
514 this.prevNick
.removeChild(this.prevNick
.menu
);
515 this.prevNick
= null;
517 nickListAdd: function(nick
, position
) {
518 var realNick
= this.client
.stripPrefix(nick
);
520 var e
= new Element("a");
521 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
524 var span
= new Element("span");
525 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
526 var colour
= realNick
.toHSBColour(this.client
);
528 span
.setStyle("color", colour
.rgbToHex());
530 span
.set("text", nick
);
533 e
.realNick
= realNick
;
535 e
.addEvent("click", function(x
) {
536 if(this.prevNick
== e
) {
537 this.removePrevMenu();
541 this.removePrevMenu();
543 e
.addClass("selected");
544 this.moveMenuClass();
545 e
.menu
= this.createMenu(e
.realNick
, e
);
549 e
.addEvent("focus", function() { this.blur() }.bind(e
));
550 this.moveMenuClass();
553 nickListRemove: function(nick
, stored
) {
554 this.nicklist
.removeChild(stored
);
555 this.moveMenuClass();
557 updateTopic: function(topic
) {
561 t
.removeChild(t
.firstChild
);
565 this.parent(topic
, t
);
568 var e
= new Element("div");
569 e
.set("text", "(no topic set)");
570 e
.addClass("emptytopic");
576 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
578 this.tab
.removeClass("tab-unselected");
579 this.tab
.addClass("tab-selected");
581 this.parentObject
.setLines(this.lines
);
582 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
583 this.parentObject
.qjsui
.showInput(inputVisible
);
584 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
), this.parentObject
.uiOptions
.SHOW_NICKLIST
);
591 this.parentObject
.inputbox
.focus();
593 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
&& this.nicksColoured
!= this.parentObject
.uiOptions
.NICK_COLOURS
) {
594 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
596 var nodes
= this.nicklist
.childNodes
;
597 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
598 for(var i
=0;i
<nodes
.length
;i
++) {
599 var e
= nodes
[i
], span
= e
.firstChild
;
600 var colour
= e
.realNick
.toHSBColour(this.client
);
602 span
.setStyle("color", colour
.rgbToHex());
605 for(var i
=0;i
<nodes
.length
;i
++) {
606 var span
= nodes
[i
].firstChild
;
607 span
.setStyle("color", null);
612 deselect: function() {
615 this.tab
.removeClass("tab-selected");
616 this.tab
.addClass("tab-unselected");
621 this.parentObject
.tabs
.removeChild(this.tab
);
622 this.parentObject
.tabs
.removeChild(this.spaceNode
);
625 addLine: function(type
, line
, colourClass
) {
626 var e
= new Element("div");
629 e
.addClass(colourClass
);
630 } else if(this.lastcolour
) {
631 e
.addClass("linestyle1");
633 e
.addClass("linestyle2");
635 this.lastcolour
= !this.lastcolour
;
637 this.parent(type
, line
, colourClass
, e
);
639 setHilighted: function(state
) {
640 var laststate
= this.hilighted
;
644 if(state
== laststate
)
647 this.tab
.removeClass("tab-hilight-activity");
648 this.tab
.removeClass("tab-hilight-us");
649 this.tab
.removeClass("tab-hilight-speech");
651 switch(this.hilighted
) {
652 case qwebirc
.ui
.HILIGHT_US:
653 this.tab
.addClass("tab-hilight-us");
655 case qwebirc
.ui
.HILIGHT_SPEECH:
656 this.tab
.addClass("tab-hilight-speech");
658 case qwebirc
.ui
.HILIGHT_ACTIVITY:
659 this.tab
.addClass("tab-hilight-activity");