]>
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 for(var i
=50;i
<1000;i
+=50)
73 this.reflow
.delay(i
, true);
74 for(var i
=1000;i
<2000;i
+=100)
76 for(var i
=2000;i
<15000;i
+=500)
79 this.setSideTabs(this.uiOptions
.SIDE_TABS
);
82 newWindow: function(client
, type
, name
) {
83 var w
= this.parent(client
, type
, name
);
84 w
.setSideTabs(this.sideTabs
);
87 __createDropdownMenu: function() {
88 var dropdownMenu
= new Element("span");
89 dropdownMenu
.addClass("dropdownmenu");
91 dropdownMenu
.hide = function() {
92 dropdownMenu
.setStyle("display", "none");
93 dropdownMenu
.visible
= false;
94 document
.removeEvent("mousedown", hideEvent
);
96 var hideEvent = function() { dropdownMenu
.hide(); };
99 this.parentElement
.appendChild(dropdownMenu
);
101 this.UICommands
.forEach(function(x
) {
104 var e
= new Element("a");
105 e
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
106 e
.addEvent("click", function() {
111 dropdownMenu
.appendChild(e
);
114 var dropdown
= new Element("div");
115 dropdown
.addClass("dropdown-tab");
116 dropdown
.appendChild(new Element("img", {src: qwebirc
.global
.staticBaseURL
+ "images/icon.png", title: "menu", alt: "menu"}));
117 dropdown
.setStyle("opacity", 1);
119 this.outerTabs
.appendChild(dropdown
);
120 dropdownMenu
.show = function(x
) {
123 if(dropdownMenu
.visible
) {
128 dropdownMenu
.setStyle("display", "inline-block");
129 dropdownMenu
.visible
= true;
131 document
.addEvent("mousedown", hideEvent
);
133 dropdown
.addEvent("mousedown", function(e
) { new Event(e
).stop(); });
134 dropdown
.addEvent("click", dropdownMenu
.show
);
136 createInput: function() {
137 var form
= new Element("form");
138 this.input
.appendChild(form
);
140 form
.addClass("input");
142 var inputbox
= new Element("input");
143 this.addEvent("signedOn", function() {
144 inputbox
.placeholder
= "chat here! you can also use commands, like /JOIN";
145 var d = function() { inputbox
.addClass("input-flash"); }.delay(250);
146 var d = function() { inputbox
.removeClass("input-flash"); }.delay(500);
147 var d = function() { inputbox
.addClass("input-flash"); }.delay(750);
148 var d = function() { inputbox
.removeClass("input-flash"); }.delay(1000);
149 var d = function() { inputbox
.addClass("input-flash"); }.delay(1250);
150 var d = function() { inputbox
.removeClass("input-flash"); }.delay(1750);
152 form
.appendChild(inputbox
);
153 this.inputbox
= inputbox
;
154 this.inputbox
.maxLength
= 470;
156 var sendInput = function() {
157 if(inputbox
.value
== "")
160 this.resetTabComplete();
161 this.getActiveWindow().historyExec(inputbox
.value
);
163 inputbox
.placeholder
= "";
166 if(!qwebirc
.util
.deviceHasKeyboard()) {
167 inputbox
.addClass("mobile-input");
168 var inputButton
= new Element("input", {type: "button"});
169 inputButton
.addClass("mobile-button");
170 inputButton
.addEvent("click", function() {
174 inputButton
.value
= ">";
175 this.input
.appendChild(inputButton
);
176 var reflowButton = function() {
177 var containerSize
= this.input
.getSize();
178 var buttonSize
= inputButton
.getSize();
180 var buttonLeft
= containerSize
.x
- buttonSize
.x
- 5; /* lovely 5 */
182 inputButton
.setStyle("left", buttonLeft
);
183 inputbox
.setStyle("width", buttonLeft
- 5);
184 inputButton
.setStyle("height", containerSize
.y
);
186 this.qjsui
.addEvent("reflow", reflowButton
);
188 inputbox
.addClass("keyboard-input");
191 form
.addEvent("submit", function(e
) {
196 var reset
= this.resetTabComplete
.bind(this);
197 inputbox
.addEvent("focus", reset
);
198 inputbox
.addEvent("mousedown", reset
);
199 inputbox
.addEvent("keypress", reset
);
201 inputbox
.addEvent("keydown", function(e
) {
203 var cvalue
= inputbox
.value
;
205 if(e
.alt
|| e
.control
|| e
.meta
)
208 if(e
.key
== "up" && !e
.shift
) {
209 resultfn
= this.commandhistory
.upLine
;
210 } else if(e
.key
== "down" && !e
.shift
) {
211 resultfn
= this.commandhistory
.downLine
;
212 } else if(e
.key
== "tab") {
213 this.tabComplete(inputbox
, e
.shift
);
222 this.resetTabComplete();
223 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
224 this.commandhistory
.addLine(cvalue
, true);
226 var result
= resultfn
.bind(this.commandhistory
)();
233 this.lastcvalue
= result
;
235 inputbox
.value
= result
;
236 qwebirc
.util
.setAtEnd(inputbox
);
239 setLines: function(lines
) {
240 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
241 this.qjsui
.middle
= this.lines
= lines
;
243 setChannelItems: function(nicklist
, topic
) {
244 if(!$defined(nicklist
)) {
245 nicklist
= this.orignicklist
;
246 topic
= this.origtopic
;
248 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
249 this.qjsui
.right
= this.nicklist
= nicklist
;
251 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
252 this.qjsui
.topic
= this.topic
= topic
;
254 setSideTabs: function(value
) {
255 if(value
=== this.sideTabs
)
258 if(this.sideTabs
=== true) {
259 this.qjsui
.left
.removeChild(this.outerTabs
);
260 } else if(this.sideTabs
=== false) {
261 this.qjsui
.top
.removeChild(this.outerTabs
);
264 this.qjsui
.left
.appendChild(this.outerTabs
);
265 this.qjsui
.top
.style
.display
= "none";
266 this.qjsui
.left
.style
.display
= "";
268 this.qjsui
.top
.appendChild(this.outerTabs
);
269 this.qjsui
.top
.style
.display
= "";
270 this.qjsui
.left
.style
.display
= "none";
272 this.sideTabs
= value
;
273 this.windows
.each(function(k
, v
) {
274 v
.each(function(k
, v2
) {
275 v2
.setSideTabs(value
);
281 qwebirc
.ui
.QUI
.JSUI
= new Class({
282 Implements: [Events
],
283 initialize: function(class_
, parent
, sizer
) {
284 this.parent
= parent
;
285 this.sizer
= $defined(sizer
)?sizer:parent
;
287 this.class_
= class_
;
290 this.reflowevent
= null;
292 window
.addEvent("resize", function() {
296 applyClasses: function(pos
, l
) {
297 l
.addClass("dynamicpanel");
298 l
.addClass(this.class_
);
299 l
.addClass(pos
+ "boundpanel");
302 var XE = function(pos
) {
303 var element
= new Element("div");
304 this.applyClasses(pos
, element
);
306 this.parent
.appendChild(element
);
310 this.top
= XE("top");
311 this.left
= XE("left");
312 this.topic
= XE("topic");
313 this.middle
= XE("middle");
314 this.right
= XE("right");
315 this.bottom
= XE("bottom");
317 reflow: function(delay
) {
322 $clear(this.reflowevent
);
324 this.reflowevent
= this.__reflow
.delay(delay
, this);
326 __reflow: function() {
327 var bottom
= this.bottom
;
328 var middle
= this.middle
;
329 var right
= this.right
;
330 var topic
= this.topic
;
332 var left
= this.left
;
334 /* |----------------------------------------------|
336 * |----------------------------------------------|
337 * | left | topic | right |
338 * | |-------------------------------| |
342 * | |---------------------------------------|
344 * |----------------------------------------------|
347 var topicsize
= topic
.getSize();
348 var topsize
= top
.getSize();
349 var rightsize
= right
.getSize();
350 var bottomsize
= bottom
.getSize();
351 var leftsize
= left
.getSize();
352 var docsize
= this.sizer
.getSize();
354 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
355 var mwidth
= (docsize
.x
- rightsize
.x
- leftsize
.x
);
357 left
.setStyle("top", topsize
.y
);
358 topic
.setStyle("top", topsize
.y
);
359 topic
.setStyle("left", leftsize
.x
);
360 topic
.setStyle("width", docsize
.x
- leftsize
.x
);
362 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
));
363 middle
.setStyle("left", leftsize
.x
);
365 middle
.setStyle("height", mheight
);
366 right
.setStyle("height", mheight
);
370 middle
.setStyle("width", mwidth
);
371 right
.setStyle("top", (topsize
.y
+ topicsize
.y
));
373 bottom
.setStyle("left", leftsize
.x
);
374 this.fireEvent("reflow");
376 showChannel: function(state
, nicklistVisible
) {
377 var display
= "none";
381 this.right
.setStyle("display", nicklistVisible
? display : "none");
382 this.topic
.setStyle("display", display
);
384 showInput: function(state
) {
385 this.bottom
.isVisible
= state
;
386 this.bottom
.setStyle("display", state
?"block":"none");
390 qwebirc
.ui
.QUI
.Window
= new Class({
391 Extends: qwebirc
.ui
.Window
,
393 initialize: function(parentObject
, client
, type
, name
, identifier
) {
394 this.parent(parentObject
, client
, type
, name
, identifier
);
396 this.tab
= new Element("a");
397 this.tab
.addClass("tab");
398 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
400 this.spaceNode
= document
.createTextNode(" ");
401 parentObject
.tabs
.appendChild(this.tab
);
402 parentObject
.tabs
.appendChild(this.spaceNode
);
404 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
405 var tabclose
= new Element("span");
406 this.tabclose
= tabclose
;
407 tabclose
.set("text", "X");
408 tabclose
.addClass("tabclose");
409 var close = function(e
) {
415 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
416 this.client
.exec("/PART " + name
);
420 //parentObject.inputbox.focus();
423 tabclose
.addEvent("click", close
);
424 this.tab
.addEvent("mouseup", function(e
) {
427 if(Browser
.Engine
.trident
)
430 if(e
.event
.button
== button
)
434 this.tab
.appendChild(tabclose
);
436 this.tabclose
= null;
439 this.tab
.appendText(name
);
440 this.tab
.addEvent("click", function(e
) {
446 parentObject
.selectWindow(this);
450 this.lines
= new Element("div");
451 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
452 this.lines
.addClass("lines");
453 if(type
!= qwebirc
.ui
.WINDOW_CUSTOM
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
)
454 this.lines
.addClass("ircwindow");
456 this.lines
.addEvent("scroll", function() {
457 this.scrolleddown
= this.scrolledDown();
458 this.scrollpos
= this.getScrollParent().getScroll();
461 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
462 this.topic
= new Element("div");
463 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
464 this.topic
.addClass("topic");
465 this.topic
.addClass("tab-invisible");
466 this.topic
.set("html", " ");
467 this.topic
.addEvent("dblclick", this.editTopic
.bind(this));
468 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
470 this.prevNick
= null;
471 this.nicklist
= new Element("div");
472 this.nicklist
.addClass("nicklist");
473 this.nicklist
.addClass("tab-invisible");
474 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
475 this.parentObject
.qjsui
.applyClasses("right", this.nicklist
);
477 this.updateTopic("");
480 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
483 rename: function(name
) {
484 var newNode
= document
.createTextNode(name
);
485 if(this.parentObject
.sideTabs
) {
486 this.tab
.replaceChild(newNode
, this.tab
.childNodes
[1]);
488 this.tab
.replaceChild(newNode
, this.tab
.firstChild
);
491 if(this.type
== qwebirc
.ui
.WINDOW_QUERY
)
492 this.updateTopic("");
494 editTopic: function() {
495 if(this.type
!= qwebirc
.ui
.WINDOW_CHANNEL
)
498 if(!this.client
.nickOnChanHasPrefix(this.client
.nickname
, this.name
, "@")) {
499 /* var cmodes = this.client.getChannelModes(channel);
500 if(cmodes.indexOf("t")) {*/
501 alert("Sorry, you need to be a channel operator to change the topic!");
505 var newTopic
= prompt("Change topic of " + this.name
+ " to:", this.topic
.topicText
);
506 if(newTopic
=== null)
509 this.client
.exec("/TOPIC " + newTopic
);
512 this.parentObject
.reflow();
514 onResize: function() {
515 if(this.scrolleddown
) {
516 if(Browser
.Engine
.trident
) {
517 this.scrollToBottom
.delay(5, this);
519 this.scrollToBottom();
521 } else if($defined(this.scrollpos
)) {
522 if(Browser
.Engine
.trident
) {
523 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
525 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
529 createMenu: function(nick
, parent
) {
530 var e
= new Element("div");
531 parent
.appendChild(e
);
534 var nickArray
= [nick
];
535 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
536 if(!x
.predicate
|| x
.predicate
!== true && !x
.predicate
.apply(this, nickArray
))
539 var e2
= new Element("a");
542 e2
.set("text", "- " + x
.text
);
544 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
545 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
.fn
); }.bind(this));
549 menuClick: function(fn
) {
551 this.prevNick.removeChild(this.prevNick.menu);
552 this.prevNick.menu = null;
554 fn
.bind(this)(this.prevNick
.realNick
);
555 this.removePrevMenu();
557 moveMenuClass: function() {
560 if(this.nicklist
.firstChild
== this.prevNick
) {
561 this.prevNick
.removeClass("selected-middle");
563 this.prevNick
.addClass("selected-middle");
566 removePrevMenu: function() {
570 this.prevNick
.removeClass("selected");
571 this.prevNick
.removeClass("selected-middle");
572 if(this.prevNick
.menu
)
573 this.prevNick
.removeChild(this.prevNick
.menu
);
574 this.prevNick
= null;
576 nickListAdd: function(nick
, position
) {
577 var realNick
= this.client
.stripPrefix(nick
);
579 var e
= new Element("a");
580 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
581 var span
= new Element("span");
582 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
583 var colour
= realNick
.toHSBColour(this.client
);
585 span
.setStyle("color", colour
.rgbToHex());
587 span
.set("text", nick
);
590 e
.realNick
= realNick
;
592 e
.addEvent("click", function(x
) {
593 if(this.prevNick
== e
) {
594 this.removePrevMenu();
598 this.removePrevMenu();
600 e
.addClass("selected");
601 this.moveMenuClass();
602 e
.menu
= this.createMenu(e
.realNick
, e
);
606 e
.addEvent("focus", function() { this.blur() }.bind(e
));
607 this.moveMenuClass();
610 nickListRemove: function(nick
, stored
) {
611 this.nicklist
.removeChild(stored
);
612 this.moveMenuClass();
614 updateTopic: function(topic
) {
618 t
.removeChild(t
.firstChild
);
621 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
626 qwebirc
.ui
.Colourise(this.name
+ suffix
, t
, null, null, this);
628 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
631 this.parent(topic
, t
);
633 t
.appendChild(document
.createTextNode("(no topic set)"));
640 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
642 this.tab
.removeClass("tab-unselected");
643 this.tab
.addClass("tab-selected");
645 this.parentObject
.setLines(this.lines
);
646 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
647 this.parentObject
.qjsui
.showInput(inputVisible
);
648 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
), this.parentObject
.uiOptions
.SHOW_NICKLIST
);
655 this.parentObject
.inputbox
.focus();
657 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
&& this.nicksColoured
!= this.parentObject
.uiOptions
.NICK_COLOURS
) {
658 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
660 var nodes
= this.nicklist
.childNodes
;
661 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
662 for(var i
=0;i
<nodes
.length
;i
++) {
663 var e
= nodes
[i
], span
= e
.firstChild
;
664 var colour
= e
.realNick
.toHSBColour(this.client
);
666 span
.setStyle("color", colour
.rgbToHex());
669 for(var i
=0;i
<nodes
.length
;i
++) {
670 var span
= nodes
[i
].firstChild
;
671 span
.setStyle("color", null);
676 deselect: function() {
679 this.tab
.removeClass("tab-selected");
680 this.tab
.addClass("tab-unselected");
685 this.parentObject
.tabs
.removeChild(this.tab
);
686 this.parentObject
.tabs
.removeChild(this.spaceNode
);
689 addLine: function(type
, line
, colourClass
) {
690 var e
= new Element("div");
693 e
.addClass(colourClass
);
694 } else if(this.lastcolour
) {
695 e
.addClass("linestyle1");
697 e
.addClass("linestyle2");
699 this.lastcolour
= !this.lastcolour
;
701 this.parent(type
, line
, colourClass
, e
);
703 setHilighted: function(state
) {
704 var laststate
= this.hilighted
;
708 if(state
== laststate
)
711 this.tab
.removeClass("tab-hilight-activity");
712 this.tab
.removeClass("tab-hilight-us");
713 this.tab
.removeClass("tab-hilight-speech");
715 switch(this.hilighted
) {
716 case qwebirc
.ui
.HILIGHT_US:
717 this.tab
.addClass("tab-hilight-us");
719 case qwebirc
.ui
.HILIGHT_SPEECH:
720 this.tab
.addClass("tab-hilight-speech");
722 case qwebirc
.ui
.HILIGHT_ACTIVITY:
723 this.tab
.addClass("tab-hilight-activity");
727 setSideTabs: function(value
) {
728 if(this.tabclose
=== null)
730 this.tab
.removeChild(this.tabclose
);
732 this.tab
.insertBefore(this.tabclose
, this.tab
.firstChild
);
734 this.tab
.appendChild(this.tabclose
);