]>
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 this.tabs
.addEvent("mousewheel", function(x
) {
47 var event
= new Event(x
);
52 } else if(event
.wheel
< 0) {
61 this.reflow
.delay(100); /* Konqueror fix */
62 this.setSideTabs(this.uiOptions
.SIDE_TABS
);
65 newWindow: function(client
, type
, name
) {
66 var w
= this.parent(client
, type
, name
);
67 w
.setSideTabs(this.sideTabs
);
70 __createDropdownMenu: function() {
71 var dropdownMenu
= new Element("span");
72 dropdownMenu
.addClass("dropdownmenu");
74 dropdownMenu
.hide = function() {
75 dropdownMenu
.setStyle("display", "none");
76 dropdownMenu
.visible
= false;
77 document
.removeEvent("mousedown", hideEvent
);
79 var hideEvent = function() { dropdownMenu
.hide(); };
82 this.parentElement
.appendChild(dropdownMenu
);
84 this.UICommands
.forEach(function(x
) {
86 var fn
= this[x
[1] + "Window"].bind(this);
87 var e
= new Element("a");
88 e
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
89 e
.addEvent("click", function() {
94 dropdownMenu
.appendChild(e
);
97 var dropdown
= new Element("div");
98 dropdown
.addClass("dropdown-tab");
99 dropdown
.appendChild(new Element("img", {src: qwebirc
.global
.staticBaseURL
+ "images/icon.png", title: "menu", alt: "menu"}));
100 dropdown
.setStyle("opacity", 1);
102 this.outerTabs
.appendChild(dropdown
);
103 dropdownMenu
.show = function(x
) {
106 if(dropdownMenu
.visible
) {
110 var parentSize
= this.outerTabs
.parentNode
.getSize().y
;
112 dropdownMenu
.setStyle("left", parentSize
.x
);
113 dropdownMenu
.setStyle("top", top
-1); /* -1 == top border */
114 dropdownMenu
.setStyle("display", "inline-block");
115 dropdownMenu
.visible
= true;
117 document
.addEvent("mousedown", hideEvent
);
119 dropdown
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
120 dropdown
.addEvent("click", dropdownMenu
.show
);
122 createInput: function() {
123 var form
= new Element("form");
124 this.input
.appendChild(form
);
126 form
.addClass("input");
128 var inputbox
= new Element("input");
129 this.addEvent("signedOn", function() {
130 inputbox
.placeholder
= "chat here! you can also use commands, like /JOIN or /HELP";
131 var d = function() { inputbox
.addClass("input-flash"); }.delay(250);
132 var d = function() { inputbox
.removeClass("input-flash"); }.delay(500);
133 var d = function() { inputbox
.addClass("input-flash"); }.delay(750);
134 var d = function() { inputbox
.removeClass("input-flash"); }.delay(1000);
135 var d = function() { inputbox
.addClass("input-flash"); }.delay(1250);
136 var d = function() { inputbox
.removeClass("input-flash"); }.delay(1750);
138 form
.appendChild(inputbox
);
139 this.inputbox
= inputbox
;
140 this.inputbox
.maxLength
= 470;
142 var sendInput = function() {
143 if(inputbox
.value
== "")
146 this.resetTabComplete();
147 this.getActiveWindow().historyExec(inputbox
.value
);
149 inputbox
.placeholder
= "";
152 if(!qwebirc
.util
.deviceHasKeyboard()) {
153 inputbox
.addClass("mobile-input");
154 var inputButton
= new Element("input", {type: "button"});
155 inputButton
.addClass("mobile-button");
156 inputButton
.addEvent("click", function() {
160 inputButton
.value
= ">";
161 this.input
.appendChild(inputButton
);
162 var reflowButton = function() {
163 var containerSize
= this.input
.getSize();
164 var buttonSize
= inputButton
.getSize();
166 var buttonLeft
= containerSize
.x
- buttonSize
.x
- 5; /* lovely 5 */
168 inputButton
.setStyle("left", buttonLeft
);
169 inputbox
.setStyle("width", buttonLeft
- 5);
170 inputButton
.setStyle("height", containerSize
.y
);
172 this.qjsui
.addEvent("reflow", reflowButton
);
174 inputbox
.addClass("keyboard-input");
177 form
.addEvent("submit", function(e
) {
182 inputbox
.addEvent("focus", this.resetTabComplete
.bind(this));
183 inputbox
.addEvent("mousedown", this.resetTabComplete
.bind(this));
185 inputbox
.addEvent("keydown", function(e
) {
187 var cvalue
= inputbox
.value
;
190 resultfn
= this.commandhistory
.upLine
;
191 } else if(e
.key
== "down") {
192 resultfn
= this.commandhistory
.downLine
;
193 } else if(e
.key
== "tab" && !e
.altKey
&& !e
.ctrlKey
&& !e
.shiftKey
) {
195 this.tabComplete(inputbox
);
198 /* ideally alt and other keys wouldn't break this */
199 this.resetTabComplete();
203 this.resetTabComplete();
204 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
205 this.commandhistory
.addLine(cvalue
, true);
207 var result
= resultfn
.bind(this.commandhistory
)();
212 this.lastcvalue
= result
;
214 inputbox
.value
= result
;
215 qwebirc
.util
.setAtEnd(inputbox
);
218 setLines: function(lines
) {
219 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
220 this.qjsui
.middle
= this.lines
= lines
;
222 setChannelItems: function(nicklist
, topic
) {
223 if(!$defined(nicklist
)) {
224 nicklist
= this.orignicklist
;
225 topic
= this.origtopic
;
227 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
228 this.qjsui
.right
= this.nicklist
= nicklist
;
230 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
231 this.qjsui
.topic
= this.topic
= topic
;
233 setSideTabs: function(value
) {
234 if(value
=== this.sideTabs
)
237 if(this.sideTabs
=== true) {
238 this.qjsui
.left
.removeChild(this.outerTabs
);
239 } else if(this.sideTabs
=== false) {
240 this.qjsui
.top
.removeChild(this.outerTabs
);
243 this.qjsui
.left
.appendChild(this.outerTabs
);
244 this.qjsui
.top
.style
.display
= "none";
245 this.qjsui
.left
.style
.display
= "";
247 this.qjsui
.top
.appendChild(this.outerTabs
);
248 this.qjsui
.top
.style
.display
= "";
249 this.qjsui
.left
.style
.display
= "none";
251 this.sideTabs
= value
;
252 this.windows
.each(function(k
, v
) {
253 v
.each(function(k
, v2
) {
254 v2
.setSideTabs(value
);
260 qwebirc
.ui
.QUI
.JSUI
= new Class({
261 Implements: [Events
],
262 initialize: function(class_
, parent
, sizer
) {
263 this.parent
= parent
;
264 this.sizer
= $defined(sizer
)?sizer:parent
;
266 this.class_
= class_
;
269 this.reflowevent
= null;
271 window
.addEvent("resize", function() {
275 applyClasses: function(pos
, l
) {
276 l
.addClass("dynamicpanel");
277 l
.addClass(this.class_
);
278 l
.addClass(pos
+ "boundpanel");
281 var XE = function(pos
) {
282 var element
= new Element("div");
283 this.applyClasses(pos
, element
);
285 this.parent
.appendChild(element
);
289 this.top
= XE("top");
290 this.left
= XE("left");
291 this.topic
= XE("topic");
292 this.middle
= XE("middle");
293 this.right
= XE("right");
294 this.bottom
= XE("bottom");
296 reflow: function(delay
) {
301 $clear(this.reflowevent
);
303 this.reflowevent
= this.__reflow
.delay(delay
, this);
305 __reflow: function() {
306 var bottom
= this.bottom
;
307 var middle
= this.middle
;
308 var right
= this.right
;
309 var topic
= this.topic
;
311 var left
= this.left
;
313 /* |----------------------------------------------|
315 * |----------------------------------------------|
316 * | left | topic | right |
317 * | |-------------------------------| |
321 * | |---------------------------------------|
323 * |----------------------------------------------|
326 var topicsize
= topic
.getSize();
327 var topsize
= top
.getSize();
328 var rightsize
= right
.getSize();
329 var bottomsize
= bottom
.getSize();
330 var leftsize
= left
.getSize();
331 var docsize
= this.sizer
.getSize();
333 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
334 var mwidth
= (docsize
.x
- rightsize
.x
- leftsize
.x
);
336 left
.setStyle("top", topsize
.y
);
337 topic
.setStyle("top", topsize
.y
);
338 topic
.setStyle("left", leftsize
.x
);
340 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
));
341 middle
.setStyle("left", leftsize
.x
);
343 middle
.setStyle("height", mheight
);
344 right
.setStyle("height", mheight
);
348 middle
.setStyle("width", mwidth
);
349 right
.setStyle("top", (topsize
.y
+ topicsize
.y
));
351 bottom
.setStyle("left", leftsize
.x
);
352 this.fireEvent("reflow");
354 showChannel: function(state
, nicklistVisible
) {
355 var display
= "none";
359 this.right
.setStyle("display", nicklistVisible
? display : "none");
360 this.topic
.setStyle("display", display
);
362 showInput: function(state
) {
363 this.bottom
.isVisible
= state
;
364 this.bottom
.setStyle("display", state
?"block":"none");
368 qwebirc
.ui
.QUI
.Window
= new Class({
369 Extends: qwebirc
.ui
.Window
,
371 initialize: function(parentObject
, client
, type
, name
, identifier
) {
372 this.parent(parentObject
, client
, type
, name
, identifier
);
374 this.tab
= new Element("a", {"href": "#"});
375 this.tab
.addClass("tab");
376 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
378 this.spaceNode
= document
.createTextNode(" ");
379 parentObject
.tabs
.appendChild(this.tab
);
380 parentObject
.tabs
.appendChild(this.spaceNode
);
382 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
383 var tabclose
= new Element("span");
384 this.tabclose
= tabclose
;
385 tabclose
.set("text", "X");
386 tabclose
.addClass("tabclose");
387 var close = function(e
) {
393 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
394 this.client
.exec("/PART " + name
);
398 //parentObject.inputbox.focus();
401 tabclose
.addEvent("click", close
);
402 this.tab
.addEvent("mouseup", function(e
) {
405 if(Browser
.Engine
.trident
)
408 if(e
.event
.button
== button
)
412 this.tab
.appendChild(tabclose
);
414 this.tabclose
= null;
417 this.tab
.appendText(name
);
418 this.tab
.addEvent("click", function(e
) {
424 parentObject
.selectWindow(this);
428 this.lines
= new Element("div");
429 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
430 this.lines
.addClass("lines");
431 if(type
!= qwebirc
.ui
.WINDOW_CUSTOM
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
)
432 this.lines
.addClass("ircwindow");
434 this.lines
.addEvent("scroll", function() {
435 this.scrolleddown
= this.scrolledDown();
436 this.scrollpos
= this.getScrollParent().getScroll();
439 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
440 this.topic
= new Element("div");
441 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
442 this.topic
.addClass("topic");
443 this.topic
.addClass("tab-invisible");
444 this.topic
.set("html", " ");
445 this.topic
.addEvent("dblclick", this.editTopic
.bind(this));
446 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
448 this.prevNick
= null;
449 this.nicklist
= new Element("div");
450 this.nicklist
.addClass("nicklist");
451 this.nicklist
.addClass("tab-invisible");
452 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
453 this.parentObject
.qjsui
.applyClasses("right", this.nicklist
);
456 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
457 this.updateTopic("");
459 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
462 rename: function(name
) {
463 this.tab
.replaceChild(document
.createTextNode(name
), this.tab
.firstChild
);
465 editTopic: function() {
466 if(!this.client
.nickOnChanHasPrefix(this.client
.nickname
, this.name
, "@")) {
467 /* var cmodes = this.client.getChannelModes(channel);
468 if(cmodes.indexOf("t")) {*/
469 alert("Sorry, you need to be a channel operator to change the topic!");
473 var newTopic
= prompt("Change topic of " + this.name
+ " to:", this.topic
.topicText
);
474 if(newTopic
=== null)
477 this.client
.exec("/TOPIC " + newTopic
);
480 this.parentObject
.reflow();
482 onResize: function() {
483 if(this.scrolleddown
) {
484 if(Browser
.Engine
.trident
) {
485 this.scrollToBottom
.delay(5, this);
487 this.scrollToBottom();
489 } else if($defined(this.scrollpos
)) {
490 if(Browser
.Engine
.trident
) {
491 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
493 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
497 createMenu: function(nick
, parent
) {
498 var e
= new Element("div");
499 parent
.appendChild(e
);
502 var nickArray
= [nick
];
503 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
504 if(!x
.predicate
|| x
.predicate
!== true && !x
.predicate
.apply(this, nickArray
))
507 var e2
= new Element("a");
511 e2
.set("text", "- " + x
.text
);
513 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
514 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
.fn
); }.bind(this));
518 menuClick: function(fn
) {
520 this.prevNick.removeChild(this.prevNick.menu);
521 this.prevNick.menu = null;
523 fn
.bind(this)(this.prevNick
.realNick
);
524 this.removePrevMenu();
526 moveMenuClass: function() {
529 if(this.nicklist
.firstChild
== this.prevNick
) {
530 this.prevNick
.removeClass("selected-middle");
532 this.prevNick
.addClass("selected-middle");
535 removePrevMenu: function() {
539 this.prevNick
.removeClass("selected");
540 this.prevNick
.removeClass("selected-middle");
541 if(this.prevNick
.menu
)
542 this.prevNick
.removeChild(this.prevNick
.menu
);
543 this.prevNick
= null;
545 nickListAdd: function(nick
, position
) {
546 var realNick
= this.client
.stripPrefix(nick
);
548 var e
= new Element("a");
549 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
552 var span
= new Element("span");
553 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
554 var colour
= realNick
.toHSBColour(this.client
);
556 span
.setStyle("color", colour
.rgbToHex());
558 span
.set("text", nick
);
561 e
.realNick
= realNick
;
563 e
.addEvent("click", function(x
) {
564 if(this.prevNick
== e
) {
565 this.removePrevMenu();
569 this.removePrevMenu();
571 e
.addClass("selected");
572 this.moveMenuClass();
573 e
.menu
= this.createMenu(e
.realNick
, e
);
577 e
.addEvent("focus", function() { this.blur() }.bind(e
));
578 this.moveMenuClass();
581 nickListRemove: function(nick
, stored
) {
582 this.nicklist
.removeChild(stored
);
583 this.moveMenuClass();
585 updateTopic: function(topic
) {
589 t
.removeChild(t
.firstChild
);
593 this.parent(topic
, t
);
596 var e
= new Element("div");
597 e
.set("text", "(no topic set)");
598 e
.addClass("emptytopic");
604 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
606 this.tab
.removeClass("tab-unselected");
607 this.tab
.addClass("tab-selected");
609 this.parentObject
.setLines(this.lines
);
610 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
611 this.parentObject
.qjsui
.showInput(inputVisible
);
612 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
), this.parentObject
.uiOptions
.SHOW_NICKLIST
);
619 this.parentObject
.inputbox
.focus();
621 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
&& this.nicksColoured
!= this.parentObject
.uiOptions
.NICK_COLOURS
) {
622 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
624 var nodes
= this.nicklist
.childNodes
;
625 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
626 for(var i
=0;i
<nodes
.length
;i
++) {
627 var e
= nodes
[i
], span
= e
.firstChild
;
628 var colour
= e
.realNick
.toHSBColour(this.client
);
630 span
.setStyle("color", colour
.rgbToHex());
633 for(var i
=0;i
<nodes
.length
;i
++) {
634 var span
= nodes
[i
].firstChild
;
635 span
.setStyle("color", null);
640 deselect: function() {
643 this.tab
.removeClass("tab-selected");
644 this.tab
.addClass("tab-unselected");
649 this.parentObject
.tabs
.removeChild(this.tab
);
650 this.parentObject
.tabs
.removeChild(this.spaceNode
);
653 addLine: function(type
, line
, colourClass
) {
654 var e
= new Element("div");
657 e
.addClass(colourClass
);
658 } else if(this.lastcolour
) {
659 e
.addClass("linestyle1");
661 e
.addClass("linestyle2");
663 this.lastcolour
= !this.lastcolour
;
665 this.parent(type
, line
, colourClass
, e
);
667 setHilighted: function(state
) {
668 var laststate
= this.hilighted
;
672 if(state
== laststate
)
675 this.tab
.removeClass("tab-hilight-activity");
676 this.tab
.removeClass("tab-hilight-us");
677 this.tab
.removeClass("tab-hilight-speech");
679 switch(this.hilighted
) {
680 case qwebirc
.ui
.HILIGHT_US:
681 this.tab
.addClass("tab-hilight-us");
683 case qwebirc
.ui
.HILIGHT_SPEECH:
684 this.tab
.addClass("tab-hilight-speech");
686 case qwebirc
.ui
.HILIGHT_ACTIVITY:
687 this.tab
.addClass("tab-hilight-activity");
691 setSideTabs: function(value
) {
692 if(this.tabclose
=== null)
694 this.tab
.removeChild(this.tabclose
);
696 this.tab
.insertBefore(this.tabclose
, this.tab
.firstChild
);
698 this.tab
.appendChild(this.tabclose
);