]>
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" && !e
.altKey
&& !e
.ctrlKey
&& !e
.shiftKey
) {
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 rename: function(name
) {
438 this.tab
.replaceChild(document
.createTextNode(name
), this.tab
.firstChild
);
440 editTopic: function() {
441 if(!this.client
.nickOnChanHasPrefix(this.client
.nickname
, this.name
, "@")) {
442 /* var cmodes = this.client.getChannelModes(channel);
443 if(cmodes.indexOf("t")) {*/
444 alert("Sorry, you need to be a channel operator to change the topic!");
448 var newTopic
= prompt("Change topic of " + this.name
+ " to:", this.topic
.topicText
);
449 if(newTopic
=== null)
452 this.client
.exec("/TOPIC " + newTopic
);
455 this.parentObject
.reflow();
457 onResize: function() {
458 if(this.scrolleddown
) {
459 if(Browser
.Engine
.trident
) {
460 this.scrollToBottom
.delay(5, this);
462 this.scrollToBottom();
464 } else if($defined(this.scrollpos
)) {
465 if(Browser
.Engine
.trident
) {
466 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
468 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
472 createMenu: function(nick
, parent
) {
473 var e
= new Element("div");
474 parent
.appendChild(e
);
477 var nickArray
= [nick
];
478 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
479 if(!x
.predicate
|| x
.predicate
!== true && !x
.predicate
.apply(this, nickArray
))
482 var e2
= new Element("a");
486 e2
.set("text", "- " + x
.text
);
488 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
489 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
.fn
); }.bind(this));
493 menuClick: function(fn
) {
495 this.prevNick.removeChild(this.prevNick.menu);
496 this.prevNick.menu = null;
498 fn
.bind(this)(this.prevNick
.realNick
);
499 this.removePrevMenu();
501 moveMenuClass: function() {
504 if(this.nicklist
.firstChild
== this.prevNick
) {
505 this.prevNick
.removeClass("selected-middle");
507 this.prevNick
.addClass("selected-middle");
510 removePrevMenu: function() {
514 this.prevNick
.removeClass("selected");
515 this.prevNick
.removeClass("selected-middle");
516 if(this.prevNick
.menu
)
517 this.prevNick
.removeChild(this.prevNick
.menu
);
518 this.prevNick
= null;
520 nickListAdd: function(nick
, position
) {
521 var realNick
= this.client
.stripPrefix(nick
);
523 var e
= new Element("a");
524 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
527 var span
= new Element("span");
528 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
529 var colour
= realNick
.toHSBColour(this.client
);
531 span
.setStyle("color", colour
.rgbToHex());
533 span
.set("text", nick
);
536 e
.realNick
= realNick
;
538 e
.addEvent("click", function(x
) {
539 if(this.prevNick
== e
) {
540 this.removePrevMenu();
544 this.removePrevMenu();
546 e
.addClass("selected");
547 this.moveMenuClass();
548 e
.menu
= this.createMenu(e
.realNick
, e
);
552 e
.addEvent("focus", function() { this.blur() }.bind(e
));
553 this.moveMenuClass();
556 nickListRemove: function(nick
, stored
) {
557 this.nicklist
.removeChild(stored
);
558 this.moveMenuClass();
560 updateTopic: function(topic
) {
564 t
.removeChild(t
.firstChild
);
568 this.parent(topic
, t
);
571 var e
= new Element("div");
572 e
.set("text", "(no topic set)");
573 e
.addClass("emptytopic");
579 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
581 this.tab
.removeClass("tab-unselected");
582 this.tab
.addClass("tab-selected");
584 this.parentObject
.setLines(this.lines
);
585 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
586 this.parentObject
.qjsui
.showInput(inputVisible
);
587 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
), this.parentObject
.uiOptions
.SHOW_NICKLIST
);
594 this.parentObject
.inputbox
.focus();
596 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
&& this.nicksColoured
!= this.parentObject
.uiOptions
.NICK_COLOURS
) {
597 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
599 var nodes
= this.nicklist
.childNodes
;
600 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
601 for(var i
=0;i
<nodes
.length
;i
++) {
602 var e
= nodes
[i
], span
= e
.firstChild
;
603 var colour
= e
.realNick
.toHSBColour(this.client
);
605 span
.setStyle("color", colour
.rgbToHex());
608 for(var i
=0;i
<nodes
.length
;i
++) {
609 var span
= nodes
[i
].firstChild
;
610 span
.setStyle("color", null);
615 deselect: function() {
618 this.tab
.removeClass("tab-selected");
619 this.tab
.addClass("tab-unselected");
624 this.parentObject
.tabs
.removeChild(this.tab
);
625 this.parentObject
.tabs
.removeChild(this.spaceNode
);
628 addLine: function(type
, line
, colourClass
) {
629 var e
= new Element("div");
632 e
.addClass(colourClass
);
633 } else if(this.lastcolour
) {
634 e
.addClass("linestyle1");
636 e
.addClass("linestyle2");
638 this.lastcolour
= !this.lastcolour
;
640 this.parent(type
, line
, colourClass
, e
);
642 setHilighted: function(state
) {
643 var laststate
= this.hilighted
;
647 if(state
== laststate
)
650 this.tab
.removeClass("tab-hilight-activity");
651 this.tab
.removeClass("tab-hilight-us");
652 this.tab
.removeClass("tab-hilight-speech");
654 switch(this.hilighted
) {
655 case qwebirc
.ui
.HILIGHT_US:
656 this.tab
.addClass("tab-hilight-us");
658 case qwebirc
.ui
.HILIGHT_SPEECH:
659 this.tab
.addClass("tab-hilight-speech");
661 case qwebirc
.ui
.HILIGHT_ACTIVITY:
662 this.tab
.addClass("tab-hilight-activity");