]>
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");
17 this.qjsui
.left
.addClass("outertabbar");
19 this.qjsui
.top
.addClass("outertabbar_top");
20 this.qjsui
.left
.addClass("outertabbar_left");
22 this.qjsui
.bottom
.addClass("input");
23 this.qjsui
.right
.addClass("nicklist");
24 this.qjsui
.topic
.addClass("topic");
25 this.qjsui
.middle
.addClass("lines");
27 this.outerTabs
= new Element("div");
30 this.tabs
= new Element("div");
31 this.tabs
.addClass("tabbar");
33 this.__createDropdownMenu();
35 this.outerTabs
.appendChild(this.tabs
);
36 this.origtopic
= this.topic
= this.qjsui
.topic
;
37 this.lines
= this.qjsui
.middle
;
38 this.orignicklist
= this.nicklist
= this.qjsui
.right
;
40 this.input
= this.qjsui
.bottom
;
41 this.reflow
= this.qjsui
.reflow
.bind(this.qjsui
);
43 var scrollHandler = function(x
) {
44 var event
= new Event(x
);
47 var p
= this.qjsui
.left
;
49 /* don't scroll if we're scrollable */
50 if(p
.getScrollSize().y
> p
.clientHeight
)
54 down
= event
.wheel
> 0;
57 down
= event
.wheel
< 0;
67 this.qjsui
.left
.addEvent("mousewheel", scrollHandler
);
68 this.qjsui
.top
.addEvent("mousewheel", scrollHandler
);
72 this.reflow
.delay(100); /* Konqueror fix */
73 this.setSideTabs(this.uiOptions
.SIDE_TABS
);
76 newWindow: function(client
, type
, name
) {
77 var w
= this.parent(client
, type
, name
);
78 w
.setSideTabs(this.sideTabs
);
81 __createDropdownMenu: function() {
82 var dropdownMenu
= new Element("span");
83 dropdownMenu
.addClass("dropdownmenu");
85 dropdownMenu
.hide = function() {
86 dropdownMenu
.setStyle("display", "none");
87 dropdownMenu
.visible
= false;
88 document
.removeEvent("mousedown", hideEvent
);
90 var hideEvent = function() { dropdownMenu
.hide(); };
93 this.parentElement
.appendChild(dropdownMenu
);
95 this.UICommands
.forEach(function(x
) {
97 var fn
= this[x
[1] + "Window"].bind(this);
98 var e
= new Element("a");
99 e
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
100 e
.addEvent("click", function() {
105 dropdownMenu
.appendChild(e
);
108 var dropdown
= new Element("div");
109 dropdown
.addClass("dropdown-tab");
110 dropdown
.appendChild(new Element("img", {src: qwebirc
.global
.staticBaseURL
+ "images/icon.png", title: "menu", alt: "menu"}));
111 dropdown
.setStyle("opacity", 1);
113 this.outerTabs
.appendChild(dropdown
);
114 dropdownMenu
.show = function(x
) {
117 if(dropdownMenu
.visible
) {
121 var parentSize
= this.outerTabs
.parentNode
.getSize().y
;
123 dropdownMenu
.setStyle("left", parentSize
.x
);
124 dropdownMenu
.setStyle("top", top
-1); /* -1 == top border */
125 dropdownMenu
.setStyle("display", "inline-block");
126 dropdownMenu
.visible
= true;
128 document
.addEvent("mousedown", hideEvent
);
130 dropdown
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
131 dropdown
.addEvent("click", dropdownMenu
.show
);
133 createInput: function() {
134 var form
= new Element("form");
135 this.input
.appendChild(form
);
137 form
.addClass("input");
139 var inputbox
= new Element("input");
140 this.addEvent("signedOn", function() {
141 inputbox
.placeholder
= "chat here! you can also use commands, like /JOIN or /HELP";
142 var d = function() { inputbox
.addClass("input-flash"); }.delay(250);
143 var d = function() { inputbox
.removeClass("input-flash"); }.delay(500);
144 var d = function() { inputbox
.addClass("input-flash"); }.delay(750);
145 var d = function() { inputbox
.removeClass("input-flash"); }.delay(1000);
146 var d = function() { inputbox
.addClass("input-flash"); }.delay(1250);
147 var d = function() { inputbox
.removeClass("input-flash"); }.delay(1750);
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
);
160 inputbox
.placeholder
= "";
163 if(!qwebirc
.util
.deviceHasKeyboard()) {
164 inputbox
.addClass("mobile-input");
165 var inputButton
= new Element("input", {type: "button"});
166 inputButton
.addClass("mobile-button");
167 inputButton
.addEvent("click", function() {
171 inputButton
.value
= ">";
172 this.input
.appendChild(inputButton
);
173 var reflowButton = function() {
174 var containerSize
= this.input
.getSize();
175 var buttonSize
= inputButton
.getSize();
177 var buttonLeft
= containerSize
.x
- buttonSize
.x
- 5; /* lovely 5 */
179 inputButton
.setStyle("left", buttonLeft
);
180 inputbox
.setStyle("width", buttonLeft
- 5);
181 inputButton
.setStyle("height", containerSize
.y
);
183 this.qjsui
.addEvent("reflow", reflowButton
);
185 inputbox
.addClass("keyboard-input");
188 form
.addEvent("submit", function(e
) {
193 var reset
= this.resetTabComplete
.bind(this);
194 inputbox
.addEvent("focus", reset
);
195 inputbox
.addEvent("mousedown", reset
);
196 inputbox
.addEvent("keypress", reset
);
198 inputbox
.addEvent("keydown", function(e
) {
200 var cvalue
= inputbox
.value
;
202 if(e
.alt
|| e
.control
|| e
.meta
)
205 if(e
.key
== "up" && !e
.shift
) {
206 resultfn
= this.commandhistory
.upLine
;
207 } else if(e
.key
== "down" && !e
.shift
) {
208 resultfn
= this.commandhistory
.downLine
;
209 } else if(e
.key
== "tab") {
210 this.tabComplete(inputbox
, e
.shift
);
219 this.resetTabComplete();
220 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
221 this.commandhistory
.addLine(cvalue
, true);
223 var result
= resultfn
.bind(this.commandhistory
)();
230 this.lastcvalue
= result
;
232 inputbox
.value
= result
;
233 qwebirc
.util
.setAtEnd(inputbox
);
236 setLines: function(lines
) {
237 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
238 this.qjsui
.middle
= this.lines
= lines
;
240 setChannelItems: function(nicklist
, topic
) {
241 if(!$defined(nicklist
)) {
242 nicklist
= this.orignicklist
;
243 topic
= this.origtopic
;
245 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
246 this.qjsui
.right
= this.nicklist
= nicklist
;
248 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
249 this.qjsui
.topic
= this.topic
= topic
;
251 setSideTabs: function(value
) {
252 if(value
=== this.sideTabs
)
255 if(this.sideTabs
=== true) {
256 this.qjsui
.left
.removeChild(this.outerTabs
);
257 } else if(this.sideTabs
=== false) {
258 this.qjsui
.top
.removeChild(this.outerTabs
);
261 this.qjsui
.left
.appendChild(this.outerTabs
);
262 this.qjsui
.top
.style
.display
= "none";
263 this.qjsui
.left
.style
.display
= "";
265 this.qjsui
.top
.appendChild(this.outerTabs
);
266 this.qjsui
.top
.style
.display
= "";
267 this.qjsui
.left
.style
.display
= "none";
269 this.sideTabs
= value
;
270 this.windows
.each(function(k
, v
) {
271 v
.each(function(k
, v2
) {
272 v2
.setSideTabs(value
);
278 qwebirc
.ui
.QUI
.JSUI
= new Class({
279 Implements: [Events
],
280 initialize: function(class_
, parent
, sizer
) {
281 this.parent
= parent
;
282 this.sizer
= $defined(sizer
)?sizer:parent
;
284 this.class_
= class_
;
287 this.reflowevent
= null;
289 window
.addEvent("resize", function() {
293 applyClasses: function(pos
, l
) {
294 l
.addClass("dynamicpanel");
295 l
.addClass(this.class_
);
296 l
.addClass(pos
+ "boundpanel");
299 var XE = function(pos
) {
300 var element
= new Element("div");
301 this.applyClasses(pos
, element
);
303 this.parent
.appendChild(element
);
307 this.top
= XE("top");
308 this.left
= XE("left");
309 this.topic
= XE("topic");
310 this.middle
= XE("middle");
311 this.right
= XE("right");
312 this.bottom
= XE("bottom");
314 reflow: function(delay
) {
319 $clear(this.reflowevent
);
321 this.reflowevent
= this.__reflow
.delay(delay
, this);
323 __reflow: function() {
324 var bottom
= this.bottom
;
325 var middle
= this.middle
;
326 var right
= this.right
;
327 var topic
= this.topic
;
329 var left
= this.left
;
331 /* |----------------------------------------------|
333 * |----------------------------------------------|
334 * | left | topic | right |
335 * | |-------------------------------| |
339 * | |---------------------------------------|
341 * |----------------------------------------------|
344 var topicsize
= topic
.getSize();
345 var topsize
= top
.getSize();
346 var rightsize
= right
.getSize();
347 var bottomsize
= bottom
.getSize();
348 var leftsize
= left
.getSize();
349 var docsize
= this.sizer
.getSize();
351 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
352 var mwidth
= (docsize
.x
- rightsize
.x
- leftsize
.x
);
354 left
.setStyle("top", topsize
.y
);
355 topic
.setStyle("top", topsize
.y
);
356 topic
.setStyle("left", leftsize
.x
);
357 topic
.setStyle("width", docsize
.x
- leftsize
.x
);
359 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
));
360 middle
.setStyle("left", leftsize
.x
);
362 middle
.setStyle("height", mheight
);
363 right
.setStyle("height", mheight
);
367 middle
.setStyle("width", mwidth
);
368 right
.setStyle("top", (topsize
.y
+ topicsize
.y
));
370 bottom
.setStyle("left", leftsize
.x
);
371 this.fireEvent("reflow");
373 showChannel: function(state
, nicklistVisible
) {
374 var display
= "none";
378 this.right
.setStyle("display", nicklistVisible
? display : "none");
379 this.topic
.setStyle("display", display
);
381 showInput: function(state
) {
382 this.bottom
.isVisible
= state
;
383 this.bottom
.setStyle("display", state
?"block":"none");
387 qwebirc
.ui
.QUI
.Window
= new Class({
388 Extends: qwebirc
.ui
.Window
,
390 initialize: function(parentObject
, client
, type
, name
, identifier
) {
391 this.parent(parentObject
, client
, type
, name
, identifier
);
393 this.tab
= new Element("a");
394 this.tab
.addClass("tab");
395 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
397 this.spaceNode
= document
.createTextNode(" ");
398 parentObject
.tabs
.appendChild(this.tab
);
399 parentObject
.tabs
.appendChild(this.spaceNode
);
401 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
402 var tabclose
= new Element("span");
403 this.tabclose
= tabclose
;
404 tabclose
.set("text", "X");
405 tabclose
.addClass("tabclose");
406 var close = function(e
) {
412 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
413 this.client
.exec("/PART " + name
);
417 //parentObject.inputbox.focus();
420 tabclose
.addEvent("click", close
);
421 this.tab
.addEvent("mouseup", function(e
) {
424 if(Browser
.Engine
.trident
)
427 if(e
.event
.button
== button
)
431 this.tab
.appendChild(tabclose
);
433 this.tabclose
= null;
436 this.tab
.appendText(name
);
437 this.tab
.addEvent("click", function(e
) {
443 parentObject
.selectWindow(this);
447 this.lines
= new Element("div");
448 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
449 this.lines
.addClass("lines");
450 if(type
!= qwebirc
.ui
.WINDOW_CUSTOM
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
)
451 this.lines
.addClass("ircwindow");
453 this.lines
.addEvent("scroll", function() {
454 this.scrolleddown
= this.scrolledDown();
455 this.scrollpos
= this.getScrollParent().getScroll();
458 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
|| type
== qwebirc
.ui
.WINDOW_QUERY
) {
459 this.topic
= new Element("div");
460 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
461 this.topic
.addClass("topic");
462 this.topic
.addClass("tab-invisible");
463 this.topic
.set("html", " ");
464 this.topic
.addEvent("dblclick", this.editTopic
.bind(this));
465 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
467 this.prevNick
= null;
468 this.nicklist
= new Element("div");
469 this.nicklist
.addClass("nicklist");
470 this.nicklist
.addClass("tab-invisible");
471 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
472 this.parentObject
.qjsui
.applyClasses("right", this.nicklist
);
474 this.updateTopic("");
477 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
480 rename: function(name
) {
481 var newNode
= document
.createTextNode(name
);
482 if(this.parentObject
.sideTabs
) {
483 this.tab
.replaceChild(newNode
, this.tab
.childNodes
[1]);
485 this.tab
.replaceChild(newNode
, this.tab
.firstChild
);
488 if(this.type
== qwebirc
.ui
.WINDOW_QUERY
)
489 this.updateTopic("");
491 editTopic: function() {
492 if(this.type
!= qwebirc
.ui
.WINDOW_CHANNEL
)
495 if(!this.client
.nickOnChanHasPrefix(this.client
.nickname
, this.name
, "@")) {
496 /* var cmodes = this.client.getChannelModes(channel);
497 if(cmodes.indexOf("t")) {*/
498 alert("Sorry, you need to be a channel operator to change the topic!");
502 var newTopic
= prompt("Change topic of " + this.name
+ " to:", this.topic
.topicText
);
503 if(newTopic
=== null)
506 this.client
.exec("/TOPIC " + newTopic
);
509 this.parentObject
.reflow();
511 onResize: function() {
512 if(this.scrolleddown
) {
513 if(Browser
.Engine
.trident
) {
514 this.scrollToBottom
.delay(5, this);
516 this.scrollToBottom();
518 } else if($defined(this.scrollpos
)) {
519 if(Browser
.Engine
.trident
) {
520 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
522 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
526 createMenu: function(nick
, parent
) {
527 var e
= new Element("div");
528 parent
.appendChild(e
);
531 var nickArray
= [nick
];
532 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
533 if(!x
.predicate
|| x
.predicate
!== true && !x
.predicate
.apply(this, nickArray
))
536 var e2
= new Element("a");
539 e2
.set("text", "- " + x
.text
);
541 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
542 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
.fn
); }.bind(this));
546 menuClick: function(fn
) {
548 this.prevNick.removeChild(this.prevNick.menu);
549 this.prevNick.menu = null;
551 fn
.bind(this)(this.prevNick
.realNick
);
552 this.removePrevMenu();
554 moveMenuClass: function() {
557 if(this.nicklist
.firstChild
== this.prevNick
) {
558 this.prevNick
.removeClass("selected-middle");
560 this.prevNick
.addClass("selected-middle");
563 removePrevMenu: function() {
567 this.prevNick
.removeClass("selected");
568 this.prevNick
.removeClass("selected-middle");
569 if(this.prevNick
.menu
)
570 this.prevNick
.removeChild(this.prevNick
.menu
);
571 this.prevNick
= null;
573 nickListAdd: function(nick
, position
) {
574 var realNick
= this.client
.stripPrefix(nick
);
576 var e
= new Element("a");
577 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
578 var span
= new Element("span");
579 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
580 var colour
= realNick
.toHSBColour(this.client
);
582 span
.setStyle("color", colour
.rgbToHex());
584 span
.set("text", nick
);
587 e
.realNick
= realNick
;
589 e
.addEvent("click", function(x
) {
590 if(this.prevNick
== e
) {
591 this.removePrevMenu();
595 this.removePrevMenu();
597 e
.addClass("selected");
598 this.moveMenuClass();
599 e
.menu
= this.createMenu(e
.realNick
, e
);
603 e
.addEvent("focus", function() { this.blur() }.bind(e
));
604 this.moveMenuClass();
607 nickListRemove: function(nick
, stored
) {
608 this.nicklist
.removeChild(stored
);
609 this.moveMenuClass();
611 updateTopic: function(topic
) {
615 t
.removeChild(t
.firstChild
);
618 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
623 qwebirc
.ui
.Colourise(this.name
+ suffix
, t
, null, null, this);
625 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
628 this.parent(topic
, t
);
630 t
.appendChild(document
.createTextNode("(no topic set)"));
637 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
639 this.tab
.removeClass("tab-unselected");
640 this.tab
.addClass("tab-selected");
642 this.parentObject
.setLines(this.lines
);
643 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
644 this.parentObject
.qjsui
.showInput(inputVisible
);
645 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
), this.parentObject
.uiOptions
.SHOW_NICKLIST
);
652 this.parentObject
.inputbox
.focus();
654 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
&& this.nicksColoured
!= this.parentObject
.uiOptions
.NICK_COLOURS
) {
655 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
657 var nodes
= this.nicklist
.childNodes
;
658 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
659 for(var i
=0;i
<nodes
.length
;i
++) {
660 var e
= nodes
[i
], span
= e
.firstChild
;
661 var colour
= e
.realNick
.toHSBColour(this.client
);
663 span
.setStyle("color", colour
.rgbToHex());
666 for(var i
=0;i
<nodes
.length
;i
++) {
667 var span
= nodes
[i
].firstChild
;
668 span
.setStyle("color", null);
673 deselect: function() {
676 this.tab
.removeClass("tab-selected");
677 this.tab
.addClass("tab-unselected");
682 this.parentObject
.tabs
.removeChild(this.tab
);
683 this.parentObject
.tabs
.removeChild(this.spaceNode
);
686 addLine: function(type
, line
, colourClass
) {
687 var e
= new Element("div");
690 e
.addClass(colourClass
);
691 } else if(this.lastcolour
) {
692 e
.addClass("linestyle1");
694 e
.addClass("linestyle2");
696 this.lastcolour
= !this.lastcolour
;
698 this.parent(type
, line
, colourClass
, e
);
700 setHilighted: function(state
) {
701 var laststate
= this.hilighted
;
705 if(state
== laststate
)
708 this.tab
.removeClass("tab-hilight-activity");
709 this.tab
.removeClass("tab-hilight-us");
710 this.tab
.removeClass("tab-hilight-speech");
712 switch(this.hilighted
) {
713 case qwebirc
.ui
.HILIGHT_US:
714 this.tab
.addClass("tab-hilight-us");
716 case qwebirc
.ui
.HILIGHT_SPEECH:
717 this.tab
.addClass("tab-hilight-speech");
719 case qwebirc
.ui
.HILIGHT_ACTIVITY:
720 this.tab
.addClass("tab-hilight-activity");
724 setSideTabs: function(value
) {
725 if(this.tabclose
=== null)
727 this.tab
.removeChild(this.tabclose
);
729 this.tab
.insertBefore(this.tabclose
, this.tab
.firstChild
);
731 this.tab
.appendChild(this.tabclose
);