]>
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 inputbox
.addEvent("focus", this.resetTabComplete
.bind(this));
194 inputbox
.addEvent("mousedown", this.resetTabComplete
.bind(this));
196 inputbox
.addEvent("keydown", function(e
) {
198 var cvalue
= inputbox
.value
;
201 resultfn
= this.commandhistory
.upLine
;
202 } else if(e
.key
== "down") {
203 resultfn
= this.commandhistory
.downLine
;
204 } else if(e
.key
== "tab" && !e
.altKey
&& !e
.ctrlKey
&& !e
.shiftKey
) {
206 this.tabComplete(inputbox
);
209 /* ideally alt and other keys wouldn't break this */
210 this.resetTabComplete();
214 this.resetTabComplete();
215 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
216 this.commandhistory
.addLine(cvalue
, true);
218 var result
= resultfn
.bind(this.commandhistory
)();
223 this.lastcvalue
= result
;
225 inputbox
.value
= result
;
226 qwebirc
.util
.setAtEnd(inputbox
);
229 setLines: function(lines
) {
230 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
231 this.qjsui
.middle
= this.lines
= lines
;
233 setChannelItems: function(nicklist
, topic
) {
234 if(!$defined(nicklist
)) {
235 nicklist
= this.orignicklist
;
236 topic
= this.origtopic
;
238 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
239 this.qjsui
.right
= this.nicklist
= nicklist
;
241 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
242 this.qjsui
.topic
= this.topic
= topic
;
244 setSideTabs: function(value
) {
245 if(value
=== this.sideTabs
)
248 if(this.sideTabs
=== true) {
249 this.qjsui
.left
.removeChild(this.outerTabs
);
250 } else if(this.sideTabs
=== false) {
251 this.qjsui
.top
.removeChild(this.outerTabs
);
254 this.qjsui
.left
.appendChild(this.outerTabs
);
255 this.qjsui
.top
.style
.display
= "none";
256 this.qjsui
.left
.style
.display
= "";
258 this.qjsui
.top
.appendChild(this.outerTabs
);
259 this.qjsui
.top
.style
.display
= "";
260 this.qjsui
.left
.style
.display
= "none";
262 this.sideTabs
= value
;
263 this.windows
.each(function(k
, v
) {
264 v
.each(function(k
, v2
) {
265 v2
.setSideTabs(value
);
271 qwebirc
.ui
.QUI
.JSUI
= new Class({
272 Implements: [Events
],
273 initialize: function(class_
, parent
, sizer
) {
274 this.parent
= parent
;
275 this.sizer
= $defined(sizer
)?sizer:parent
;
277 this.class_
= class_
;
280 this.reflowevent
= null;
282 window
.addEvent("resize", function() {
286 applyClasses: function(pos
, l
) {
287 l
.addClass("dynamicpanel");
288 l
.addClass(this.class_
);
289 l
.addClass(pos
+ "boundpanel");
292 var XE = function(pos
) {
293 var element
= new Element("div");
294 this.applyClasses(pos
, element
);
296 this.parent
.appendChild(element
);
300 this.top
= XE("top");
301 this.left
= XE("left");
302 this.topic
= XE("topic");
303 this.middle
= XE("middle");
304 this.right
= XE("right");
305 this.bottom
= XE("bottom");
307 reflow: function(delay
) {
312 $clear(this.reflowevent
);
314 this.reflowevent
= this.__reflow
.delay(delay
, this);
316 __reflow: function() {
317 var bottom
= this.bottom
;
318 var middle
= this.middle
;
319 var right
= this.right
;
320 var topic
= this.topic
;
322 var left
= this.left
;
324 /* |----------------------------------------------|
326 * |----------------------------------------------|
327 * | left | topic | right |
328 * | |-------------------------------| |
332 * | |---------------------------------------|
334 * |----------------------------------------------|
337 var topicsize
= topic
.getSize();
338 var topsize
= top
.getSize();
339 var rightsize
= right
.getSize();
340 var bottomsize
= bottom
.getSize();
341 var leftsize
= left
.getSize();
342 var docsize
= this.sizer
.getSize();
344 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
345 var mwidth
= (docsize
.x
- rightsize
.x
- leftsize
.x
);
347 left
.setStyle("top", topsize
.y
);
348 topic
.setStyle("top", topsize
.y
);
349 topic
.setStyle("left", leftsize
.x
);
350 topic
.setStyle("width", docsize
.x
- leftsize
.x
);
352 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
));
353 middle
.setStyle("left", leftsize
.x
);
355 middle
.setStyle("height", mheight
);
356 right
.setStyle("height", mheight
);
360 middle
.setStyle("width", mwidth
);
361 right
.setStyle("top", (topsize
.y
+ topicsize
.y
));
363 bottom
.setStyle("left", leftsize
.x
);
364 this.fireEvent("reflow");
366 showChannel: function(state
, nicklistVisible
) {
367 var display
= "none";
371 this.right
.setStyle("display", nicklistVisible
? display : "none");
372 this.topic
.setStyle("display", display
);
374 showInput: function(state
) {
375 this.bottom
.isVisible
= state
;
376 this.bottom
.setStyle("display", state
?"block":"none");
380 qwebirc
.ui
.QUI
.Window
= new Class({
381 Extends: qwebirc
.ui
.Window
,
383 initialize: function(parentObject
, client
, type
, name
, identifier
) {
384 this.parent(parentObject
, client
, type
, name
, identifier
);
386 this.tab
= new Element("a");
387 this.tab
.addClass("tab");
388 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
390 this.spaceNode
= document
.createTextNode(" ");
391 parentObject
.tabs
.appendChild(this.tab
);
392 parentObject
.tabs
.appendChild(this.spaceNode
);
394 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
395 var tabclose
= new Element("span");
396 this.tabclose
= tabclose
;
397 tabclose
.set("text", "X");
398 tabclose
.addClass("tabclose");
399 var close = function(e
) {
405 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
406 this.client
.exec("/PART " + name
);
410 //parentObject.inputbox.focus();
413 tabclose
.addEvent("click", close
);
414 this.tab
.addEvent("mouseup", function(e
) {
417 if(Browser
.Engine
.trident
)
420 if(e
.event
.button
== button
)
424 this.tab
.appendChild(tabclose
);
426 this.tabclose
= null;
429 this.tab
.appendText(name
);
430 this.tab
.addEvent("click", function(e
) {
436 parentObject
.selectWindow(this);
440 this.lines
= new Element("div");
441 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
442 this.lines
.addClass("lines");
443 if(type
!= qwebirc
.ui
.WINDOW_CUSTOM
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
)
444 this.lines
.addClass("ircwindow");
446 this.lines
.addEvent("scroll", function() {
447 this.scrolleddown
= this.scrolledDown();
448 this.scrollpos
= this.getScrollParent().getScroll();
451 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
|| type
== qwebirc
.ui
.WINDOW_QUERY
) {
452 this.topic
= new Element("div");
453 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
454 this.topic
.addClass("topic");
455 this.topic
.addClass("tab-invisible");
456 this.topic
.set("html", " ");
457 this.topic
.addEvent("dblclick", this.editTopic
.bind(this));
458 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
460 this.prevNick
= null;
461 this.nicklist
= new Element("div");
462 this.nicklist
.addClass("nicklist");
463 this.nicklist
.addClass("tab-invisible");
464 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
465 this.parentObject
.qjsui
.applyClasses("right", this.nicklist
);
467 this.updateTopic("");
470 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
473 rename: function(name
) {
474 var newNode
= document
.createTextNode(name
);
475 if(this.parentObject
.sideTabs
) {
476 this.tab
.replaceChild(newNode
, this.tab
.childNodes
[1]);
478 this.tab
.replaceChild(newNode
, this.tab
.firstChild
);
481 if(this.type
== qwebirc
.ui
.WINDOW_QUERY
)
482 this.updateTopic("");
484 editTopic: function() {
485 if(this.type
!= qwebirc
.ui
.WINDOW_CHANNEL
)
488 if(!this.client
.nickOnChanHasPrefix(this.client
.nickname
, this.name
, "@")) {
489 /* var cmodes = this.client.getChannelModes(channel);
490 if(cmodes.indexOf("t")) {*/
491 alert("Sorry, you need to be a channel operator to change the topic!");
495 var newTopic
= prompt("Change topic of " + this.name
+ " to:", this.topic
.topicText
);
496 if(newTopic
=== null)
499 this.client
.exec("/TOPIC " + newTopic
);
502 this.parentObject
.reflow();
504 onResize: function() {
505 if(this.scrolleddown
) {
506 if(Browser
.Engine
.trident
) {
507 this.scrollToBottom
.delay(5, this);
509 this.scrollToBottom();
511 } else if($defined(this.scrollpos
)) {
512 if(Browser
.Engine
.trident
) {
513 this.getScrollParent().scrollTo(this.scrollpos
.x
, this.scrollpos
.y
);
515 this.getScrollParent().scrollTo
.delay(5, this, [this.scrollpos
.x
, this.scrollpos
.y
]);
519 createMenu: function(nick
, parent
) {
520 var e
= new Element("div");
521 parent
.appendChild(e
);
524 var nickArray
= [nick
];
525 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
526 if(!x
.predicate
|| x
.predicate
!== true && !x
.predicate
.apply(this, nickArray
))
529 var e2
= new Element("a");
532 e2
.set("text", "- " + x
.text
);
534 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
535 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
.fn
); }.bind(this));
539 menuClick: function(fn
) {
541 this.prevNick.removeChild(this.prevNick.menu);
542 this.prevNick.menu = null;
544 fn
.bind(this)(this.prevNick
.realNick
);
545 this.removePrevMenu();
547 moveMenuClass: function() {
550 if(this.nicklist
.firstChild
== this.prevNick
) {
551 this.prevNick
.removeClass("selected-middle");
553 this.prevNick
.addClass("selected-middle");
556 removePrevMenu: function() {
560 this.prevNick
.removeClass("selected");
561 this.prevNick
.removeClass("selected-middle");
562 if(this.prevNick
.menu
)
563 this.prevNick
.removeChild(this.prevNick
.menu
);
564 this.prevNick
= null;
566 nickListAdd: function(nick
, position
) {
567 var realNick
= this.client
.stripPrefix(nick
);
569 var e
= new Element("a");
570 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
571 var span
= new Element("span");
572 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
573 var colour
= realNick
.toHSBColour(this.client
);
575 span
.setStyle("color", colour
.rgbToHex());
577 span
.set("text", nick
);
580 e
.realNick
= realNick
;
582 e
.addEvent("click", function(x
) {
583 if(this.prevNick
== e
) {
584 this.removePrevMenu();
588 this.removePrevMenu();
590 e
.addClass("selected");
591 this.moveMenuClass();
592 e
.menu
= this.createMenu(e
.realNick
, e
);
596 e
.addEvent("focus", function() { this.blur() }.bind(e
));
597 this.moveMenuClass();
600 nickListRemove: function(nick
, stored
) {
601 this.nicklist
.removeChild(stored
);
602 this.moveMenuClass();
604 updateTopic: function(topic
) {
608 t
.removeChild(t
.firstChild
);
611 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
616 qwebirc
.ui
.Colourise(this.name
+ suffix
, t
, null, null, this);
618 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
621 this.parent(topic
, t
);
623 t
.appendChild(document
.createTextNode("(no topic set)"));
630 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
632 this.tab
.removeClass("tab-unselected");
633 this.tab
.addClass("tab-selected");
635 this.parentObject
.setLines(this.lines
);
636 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
637 this.parentObject
.qjsui
.showInput(inputVisible
);
638 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
), this.parentObject
.uiOptions
.SHOW_NICKLIST
);
645 this.parentObject
.inputbox
.focus();
647 if(this.type
== qwebirc
.ui
.WINDOW_CHANNEL
&& this.nicksColoured
!= this.parentObject
.uiOptions
.NICK_COLOURS
) {
648 this.nicksColoured
= this.parentObject
.uiOptions
.NICK_COLOURS
;
650 var nodes
= this.nicklist
.childNodes
;
651 if(this.parentObject
.uiOptions
.NICK_COLOURS
) {
652 for(var i
=0;i
<nodes
.length
;i
++) {
653 var e
= nodes
[i
], span
= e
.firstChild
;
654 var colour
= e
.realNick
.toHSBColour(this.client
);
656 span
.setStyle("color", colour
.rgbToHex());
659 for(var i
=0;i
<nodes
.length
;i
++) {
660 var span
= nodes
[i
].firstChild
;
661 span
.setStyle("color", null);
666 deselect: function() {
669 this.tab
.removeClass("tab-selected");
670 this.tab
.addClass("tab-unselected");
675 this.parentObject
.tabs
.removeChild(this.tab
);
676 this.parentObject
.tabs
.removeChild(this.spaceNode
);
679 addLine: function(type
, line
, colourClass
) {
680 var e
= new Element("div");
683 e
.addClass(colourClass
);
684 } else if(this.lastcolour
) {
685 e
.addClass("linestyle1");
687 e
.addClass("linestyle2");
689 this.lastcolour
= !this.lastcolour
;
691 this.parent(type
, line
, colourClass
, e
);
693 setHilighted: function(state
) {
694 var laststate
= this.hilighted
;
698 if(state
== laststate
)
701 this.tab
.removeClass("tab-hilight-activity");
702 this.tab
.removeClass("tab-hilight-us");
703 this.tab
.removeClass("tab-hilight-speech");
705 switch(this.hilighted
) {
706 case qwebirc
.ui
.HILIGHT_US:
707 this.tab
.addClass("tab-hilight-us");
709 case qwebirc
.ui
.HILIGHT_SPEECH:
710 this.tab
.addClass("tab-hilight-speech");
712 case qwebirc
.ui
.HILIGHT_ACTIVITY:
713 this.tab
.addClass("tab-hilight-activity");
717 setSideTabs: function(value
) {
718 if(this.tabclose
=== null)
720 this.tab
.removeChild(this.tabclose
);
722 this.tab
.insertBefore(this.tabclose
, this.tab
.firstChild
);
724 this.tab
.appendChild(this.tabclose
);