]>
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
) {
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;
70 this.reflow
.delay(100); /* Konqueror fix */
71 this.setSideTabs(this.uiOptions
.SIDE_TABS
);
74 newWindow: function(client
, type
, name
) {
75 var w
= this.parent(client
, type
, name
);
76 w
.setSideTabs(this.sideTabs
);
79 __createDropdownMenu: function() {
80 var dropdownMenu
= new Element("span");
81 dropdownMenu
.addClass("dropdownmenu");
83 dropdownMenu
.hide = function() {
84 dropdownMenu
.setStyle("display", "none");
85 dropdownMenu
.visible
= false;
86 document
.removeEvent("mousedown", hideEvent
);
88 var hideEvent = function() { dropdownMenu
.hide(); };
91 this.parentElement
.appendChild(dropdownMenu
);
93 this.UICommands
.forEach(function(x
) {
95 var fn
= this[x
[1] + "Window"].bind(this);
96 var e
= new Element("a");
97 e
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
98 e
.addEvent("click", function() {
103 dropdownMenu
.appendChild(e
);
106 var dropdown
= new Element("div");
107 dropdown
.addClass("dropdown-tab");
108 dropdown
.appendChild(new Element("img", {src: qwebirc
.global
.staticBaseURL
+ "images/icon.png", title: "menu", alt: "menu"}));
109 dropdown
.setStyle("opacity", 1);
111 this.outerTabs
.appendChild(dropdown
);
112 dropdownMenu
.show = function(x
) {
115 if(dropdownMenu
.visible
) {
119 var parentSize
= this.outerTabs
.parentNode
.getSize().y
;
121 dropdownMenu
.setStyle("left", parentSize
.x
);
122 dropdownMenu
.setStyle("top", top
-1); /* -1 == top border */
123 dropdownMenu
.setStyle("display", "inline-block");
124 dropdownMenu
.visible
= true;
126 document
.addEvent("mousedown", hideEvent
);
128 dropdown
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
129 dropdown
.addEvent("click", dropdownMenu
.show
);
131 createInput: function() {
132 var form
= new Element("form");
133 this.input
.appendChild(form
);
135 form
.addClass("input");
137 var inputbox
= new Element("input");
138 this.addEvent("signedOn", function() {
139 inputbox
.placeholder
= "chat here! you can also use commands, like /JOIN or /HELP";
140 var d = function() { inputbox
.addClass("input-flash"); }.delay(250);
141 var d = function() { inputbox
.removeClass("input-flash"); }.delay(500);
142 var d = function() { inputbox
.addClass("input-flash"); }.delay(750);
143 var d = function() { inputbox
.removeClass("input-flash"); }.delay(1000);
144 var d = function() { inputbox
.addClass("input-flash"); }.delay(1250);
145 var d = function() { inputbox
.removeClass("input-flash"); }.delay(1750);
147 form
.appendChild(inputbox
);
148 this.inputbox
= inputbox
;
149 this.inputbox
.maxLength
= 470;
151 var sendInput = function() {
152 if(inputbox
.value
== "")
155 this.resetTabComplete();
156 this.getActiveWindow().historyExec(inputbox
.value
);
158 inputbox
.placeholder
= "";
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" && !e
.altKey
&& !e
.ctrlKey
&& !e
.shiftKey
) {
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
;
242 setSideTabs: function(value
) {
243 if(value
=== this.sideTabs
)
246 if(this.sideTabs
=== true) {
247 this.qjsui
.left
.removeChild(this.outerTabs
);
248 } else if(this.sideTabs
=== false) {
249 this.qjsui
.top
.removeChild(this.outerTabs
);
252 this.qjsui
.left
.appendChild(this.outerTabs
);
253 this.qjsui
.top
.style
.display
= "none";
254 this.qjsui
.left
.style
.display
= "";
256 this.qjsui
.top
.appendChild(this.outerTabs
);
257 this.qjsui
.top
.style
.display
= "";
258 this.qjsui
.left
.style
.display
= "none";
260 this.sideTabs
= value
;
261 this.windows
.each(function(k
, v
) {
262 v
.each(function(k
, v2
) {
263 v2
.setSideTabs(value
);
269 qwebirc
.ui
.QUI
.JSUI
= new Class({
270 Implements: [Events
],
271 initialize: function(class_
, parent
, sizer
) {
272 this.parent
= parent
;
273 this.sizer
= $defined(sizer
)?sizer:parent
;
275 this.class_
= class_
;
278 this.reflowevent
= null;
280 window
.addEvent("resize", function() {
284 applyClasses: function(pos
, l
) {
285 l
.addClass("dynamicpanel");
286 l
.addClass(this.class_
);
287 l
.addClass(pos
+ "boundpanel");
290 var XE = function(pos
) {
291 var element
= new Element("div");
292 this.applyClasses(pos
, element
);
294 this.parent
.appendChild(element
);
298 this.top
= XE("top");
299 this.left
= XE("left");
300 this.topic
= XE("topic");
301 this.middle
= XE("middle");
302 this.right
= XE("right");
303 this.bottom
= XE("bottom");
305 reflow: function(delay
) {
310 $clear(this.reflowevent
);
312 this.reflowevent
= this.__reflow
.delay(delay
, this);
314 __reflow: function() {
315 var bottom
= this.bottom
;
316 var middle
= this.middle
;
317 var right
= this.right
;
318 var topic
= this.topic
;
320 var left
= this.left
;
322 /* |----------------------------------------------|
324 * |----------------------------------------------|
325 * | left | topic | right |
326 * | |-------------------------------| |
330 * | |---------------------------------------|
332 * |----------------------------------------------|
335 var topicsize
= topic
.getSize();
336 var topsize
= top
.getSize();
337 var rightsize
= right
.getSize();
338 var bottomsize
= bottom
.getSize();
339 var leftsize
= left
.getSize();
340 var docsize
= this.sizer
.getSize();
342 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
343 var mwidth
= (docsize
.x
- rightsize
.x
- leftsize
.x
);
345 left
.setStyle("top", topsize
.y
);
346 topic
.setStyle("top", topsize
.y
);
347 topic
.setStyle("left", leftsize
.x
);
348 topic
.setStyle("width", docsize
.x
- leftsize
.x
);
350 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
));
351 middle
.setStyle("left", leftsize
.x
);
353 middle
.setStyle("height", mheight
);
354 right
.setStyle("height", mheight
);
358 middle
.setStyle("width", mwidth
);
359 right
.setStyle("top", (topsize
.y
+ topicsize
.y
));
361 bottom
.setStyle("left", leftsize
.x
);
362 this.fireEvent("reflow");
364 showChannel: function(state
, nicklistVisible
) {
365 var display
= "none";
369 this.right
.setStyle("display", nicklistVisible
? display : "none");
370 this.topic
.setStyle("display", display
);
372 showInput: function(state
) {
373 this.bottom
.isVisible
= state
;
374 this.bottom
.setStyle("display", state
?"block":"none");
378 qwebirc
.ui
.QUI
.Window
= new Class({
379 Extends: qwebirc
.ui
.Window
,
381 initialize: function(parentObject
, client
, type
, name
, identifier
) {
382 this.parent(parentObject
, client
, type
, name
, identifier
);
384 this.tab
= new Element("a");
385 this.tab
.addClass("tab");
386 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
388 this.spaceNode
= document
.createTextNode(" ");
389 parentObject
.tabs
.appendChild(this.tab
);
390 parentObject
.tabs
.appendChild(this.spaceNode
);
392 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
393 var tabclose
= new Element("span");
394 this.tabclose
= tabclose
;
395 tabclose
.set("text", "X");
396 tabclose
.addClass("tabclose");
397 var close = function(e
) {
403 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
404 this.client
.exec("/PART " + name
);
408 //parentObject.inputbox.focus();
411 tabclose
.addEvent("click", close
);
412 this.tab
.addEvent("mouseup", function(e
) {
415 if(Browser
.Engine
.trident
)
418 if(e
.event
.button
== button
)
422 this.tab
.appendChild(tabclose
);
424 this.tabclose
= null;
427 this.tab
.appendText(name
);
428 this.tab
.addEvent("click", function(e
) {
434 parentObject
.selectWindow(this);
438 this.lines
= new Element("div");
439 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
440 this.lines
.addClass("lines");
441 if(type
!= qwebirc
.ui
.WINDOW_CUSTOM
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
)
442 this.lines
.addClass("ircwindow");
444 this.lines
.addEvent("scroll", function() {
445 this.scrolleddown
= this.scrolledDown();
446 this.scrollpos
= this.getScrollParent().getScroll();
449 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
450 this.topic
= new Element("div");
451 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
452 this.topic
.addClass("topic");
453 this.topic
.addClass("tab-invisible");
454 this.topic
.set("html", " ");
455 this.topic
.addEvent("dblclick", this.editTopic
.bind(this));
456 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
458 this.prevNick
= null;
459 this.nicklist
= new Element("div");
460 this.nicklist
.addClass("nicklist");
461 this.nicklist
.addClass("tab-invisible");
462 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
463 this.parentObject
.qjsui
.applyClasses("right", this.nicklist
);
466 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
467 this.updateTopic("");
469 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
472 rename: function(name
) {
473 this.tab
.replaceChild(document
.createTextNode(name
), this.tab
.firstChild
);
475 editTopic: function() {
476 if(!this.client
.nickOnChanHasPrefix(this.client
.nickname
, this.name
, "@")) {
477 /* var cmodes = this.client.getChannelModes(channel);
478 if(cmodes.indexOf("t")) {*/
479 alert("Sorry, you need to be a channel operator to change the topic!");
483 var newTopic
= prompt("Change topic of " + this.name
+ " to:", this.topic
.topicText
);
484 if(newTopic
=== null)
487 this.client
.exec("/TOPIC " + newTopic
);
490 this.parentObject
.reflow();
492 onResize: function() {
493 if(this.scrolleddown
) {
494 if(Browser
.Engine
.trident
) {
495 this.scrollToBottom
.delay(5, this);
497 this.scrollToBottom();
499 } else if($defined(this.scrollpos
)) {
500 if(Browser
.Engine
.trident
) {
501 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
503 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
507 createMenu: function(nick
, parent
) {
508 var e
= new Element("div");
509 parent
.appendChild(e
);
512 var nickArray
= [nick
];
513 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
514 if(!x
.predicate
|| x
.predicate
!== true && !x
.predicate
.apply(this, nickArray
))
517 var e2
= new Element("a");
520 e2
.set("text", "- " + x
.text
);
522 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
523 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
.fn
); }.bind(this));
527 menuClick: function(fn
) {
529 this.prevNick.removeChild(this.prevNick.menu);
530 this.prevNick.menu = null;
532 fn
.bind(this)(this.prevNick
.realNick
);
533 this.removePrevMenu();
535 moveMenuClass: function() {
538 if(this.nicklist
.firstChild
== this.prevNick
) {
539 this.prevNick
.removeClass("selected-middle");
541 this.prevNick
.addClass("selected-middle");
544 removePrevMenu: function() {
548 this.prevNick
.removeClass("selected");
549 this.prevNick
.removeClass("selected-middle");
550 if(this.prevNick
.menu
)
551 this.prevNick
.removeChild(this.prevNick
.menu
);
552 this.prevNick
= null;
554 nickListAdd: function(nick
, position
) {
555 var realNick
= this.client
.stripPrefix(nick
);
557 var e
= new Element("a");
558 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
559 var span
= new Element("span");
560 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
561 var colour
= realNick
.toHSBColour(this.client
);
563 span
.setStyle("color", colour
.rgbToHex());
565 span
.set("text", nick
);
568 e
.realNick
= realNick
;
570 e
.addEvent("click", function(x
) {
571 if(this.prevNick
== e
) {
572 this.removePrevMenu();
576 this.removePrevMenu();
578 e
.addClass("selected");
579 this.moveMenuClass();
580 e
.menu
= this.createMenu(e
.realNick
, e
);
584 e
.addEvent("focus", function() { this.blur() }.bind(e
));
585 this.moveMenuClass();
588 nickListRemove: function(nick
, stored
) {
589 this.nicklist
.removeChild(stored
);
590 this.moveMenuClass();
592 updateTopic: function(topic
) {
596 t
.removeChild(t
.firstChild
);
600 this.parent(topic
, t
);
603 var e
= new Element("div");
604 e
.set("text", "(no topic set)");
605 e
.addClass("emptytopic");
611 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
613 this.tab
.removeClass("tab-unselected");
614 this.tab
.addClass("tab-selected");
616 this.parentObject
.setLines(this.lines
);
617 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
618 this.parentObject
.qjsui
.showInput(inputVisible
);
619 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
), this.parentObject
.uiOptions
.SHOW_NICKLIST
);
626 this.parentObject
.inputbox
.focus();
628 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
&& this.nicksColoured
!= this.parentObject
.uiOptions
.NICK_COLOURS
) {
629 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
631 var nodes
= this.nicklist
.childNodes
;
632 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
633 for(var i
=0;i
<nodes
.length
;i
++) {
634 var e
= nodes
[i
], span
= e
.firstChild
;
635 var colour
= e
.realNick
.toHSBColour(this.client
);
637 span
.setStyle("color", colour
.rgbToHex());
640 for(var i
=0;i
<nodes
.length
;i
++) {
641 var span
= nodes
[i
].firstChild
;
642 span
.setStyle("color", null);
647 deselect: function() {
650 this.tab
.removeClass("tab-selected");
651 this.tab
.addClass("tab-unselected");
656 this.parentObject
.tabs
.removeChild(this.tab
);
657 this.parentObject
.tabs
.removeChild(this.spaceNode
);
660 addLine: function(type
, line
, colourClass
) {
661 var e
= new Element("div");
664 e
.addClass(colourClass
);
665 } else if(this.lastcolour
) {
666 e
.addClass("linestyle1");
668 e
.addClass("linestyle2");
670 this.lastcolour
= !this.lastcolour
;
672 this.parent(type
, line
, colourClass
, e
);
674 setHilighted: function(state
) {
675 var laststate
= this.hilighted
;
679 if(state
== laststate
)
682 this.tab
.removeClass("tab-hilight-activity");
683 this.tab
.removeClass("tab-hilight-us");
684 this.tab
.removeClass("tab-hilight-speech");
686 switch(this.hilighted
) {
687 case qwebirc
.ui
.HILIGHT_US:
688 this.tab
.addClass("tab-hilight-us");
690 case qwebirc
.ui
.HILIGHT_SPEECH:
691 this.tab
.addClass("tab-hilight-speech");
693 case qwebirc
.ui
.HILIGHT_ACTIVITY:
694 this.tab
.addClass("tab-hilight-activity");
698 setSideTabs: function(value
) {
699 if(this.tabclose
=== null)
701 this.tab
.removeChild(this.tabclose
);
703 this.tab
.insertBefore(this.tabclose
, this.tab
.firstChild
);
705 this.tab
.appendChild(this.tabclose
);