]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/qui.js
1 qwebirc
.ui
.QUI
= new Class({
2 Extends: qwebirc
.ui
.NewLoginUI
,
3 initialize: function(parentElement
, theme
) {
4 this.parent(parentElement
, qwebirc
.ui
.QUI
.Window
, "qui");
6 this.parentElement
= parentElement
;
8 postInitialize: function() {
9 this.qjsui
= new qwebirc
.ui
.QUI
.JSUI("qwebirc-qui", this.parentElement
);
11 this.qjsui
.top
.addClass("tabbar");
13 this.qjsui
.bottom
.addClass("input");
14 this.qjsui
.right
.addClass("nicklist");
15 this.qjsui
.topic
.addClass("topic");
16 this.qjsui
.middle
.addClass("lines");
18 this.tabs
= this.qjsui
.top
;
19 this.origtopic
= this.topic
= this.qjsui
.topic
;
20 this.origlines
= this.lines
= this.qjsui
.middle
;
21 this.orignicklist
= this.nicklist
= this.qjsui
.right
;
23 this.input
= this.qjsui
.bottom
;
24 this.reflow
= this.qjsui
.reflow
.bind(this.qjsui
);
26 this.tabs
.addEvent("mousewheel", function(x
) {
27 var event
= new Event(x
);
32 } else if(event
.wheel
< 0) {
42 createInput: function() {
43 var form
= new Element("form");
44 this.input
.appendChild(form
);
45 form
.addClass("input");
47 var inputbox
= new Element("input");
48 form
.appendChild(inputbox
);
49 this.inputbox
= inputbox
;
51 form
.addEvent("submit", function(e
) {
54 if(inputbox
.value
== "")
57 this.getActiveWindow().historyExec(inputbox
.value
);
61 inputbox
.addEvent("keydown", function(e
) {
63 var cvalue
= inputbox
.value
;
66 resultfn
= this.commandhistory
.upLine
;
67 } else if(e
.key
== "down") {
68 resultfn
= this.commandhistory
.downLine
;
73 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
74 this.commandhistory
.addLine(cvalue
, true);
76 var result
= resultfn
.bind(this.commandhistory
)();
81 this.lastcvalue
= result
;
83 inputbox
.value
= result
;
84 qwebirc
.util
.setAtEnd(inputbox
);
87 setLines: function(lines
) {
88 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
89 this.qjsui
.middle
= this.lines
= lines
;
91 setChannelItems: function(nicklist
, topic
) {
92 if(!$defined(nicklist
)) {
93 nicklist
= this.orignicklist
;
94 topic
= this.origtopic
;
96 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
97 this.qjsui
.right
= this.nicklist
= nicklist
;
99 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
100 this.qjsui
.topic
= this.topic
= topic
;
104 qwebirc
.ui
.QUI
.JSUI
= new Class({
105 initialize: function(class_
, parent
, sizer
) {
106 this.parent
= parent
;
107 this.sizer
= $defined(sizer
)?sizer:parent
;
109 this.class_
= class_
;
112 this.reflowevent
= null;
114 window
.addEvent("resize", function() {
118 applyClasses: function(pos
, l
) {
119 l
.addClass("dynamicpanel");
120 l
.addClass(this.class_
);
122 if(pos
== "middle") {
123 l
.addClass("leftboundpanel");
124 } else if(pos
== "top") {
125 l
.addClass("topboundpanel");
126 l
.addClass("widepanel");
127 } else if(pos
== "topic") {
128 l
.addClass("widepanel");
129 } else if(pos
== "right") {
130 l
.addClass("rightboundpanel");
131 } else if(pos
== "bottom") {
132 l
.addClass("bottomboundpanel");
133 l
.addClass("widepanel");
137 var XE = function(pos
) {
138 var element
= new Element("div");
139 this.applyClasses(pos
, element
);
141 this.parent
.appendChild(element
);
145 this.top
= XE("top");
146 this.topic
= XE("topic");
147 this.middle
= XE("middle");
148 this.right
= XE("right");
149 this.bottom
= XE("bottom");
151 reflow: function(delay
) {
156 $clear(this.reflowevent
);
158 this.reflowevent
= this.__reflow
.delay(delay
, this);
160 __reflow: function() {
161 var bottom
= this.bottom
;
162 var middle
= this.middle
;
163 var right
= this.right
;
164 var topic
= this.topic
;
167 var topicsize
= topic
.getSize();
168 var topsize
= top
.getSize();
169 var rightsize
= right
.getSize();
170 var bottomsize
= bottom
.getSize();
171 var docsize
= this.sizer
.getSize();
173 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
174 var mwidth
= (docsize
.x
- rightsize
.x
);
176 topic
.setStyle("top", topsize
.y
+ "px");
178 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
180 middle
.setStyle("height", mheight
+ "px");
181 right
.setStyle("height", mheight
+ "px");
185 middle
.setStyle("width", mwidth
+ "px");
186 right
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
187 right
.setStyle("left", mwidth
+ "px");
189 bottom
.setStyle("top", (docsize
.y
- bottomsize
.y
) + "px");
191 showChannel: function(state
) {
192 var display
= "none";
196 this.right
.setStyle("display", display
);
197 this.topic
.setStyle("display", display
);
199 showInput: function(state
) {
200 this.bottom
.setStyle("display", state
?"block":"none");
204 qwebirc
.ui
.QUI
.Window
= new Class({
205 Extends: qwebirc
.ui
.Window
,
207 initialize: function(parentObject
, client
, type
, name
) {
208 this.parent(parentObject
, client
, type
, name
);
210 this.tab
= new Element("a", {"href": "#"});
211 this.tab
.addClass("tab");
212 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
214 parentObject
.tabs
.appendChild(this.tab
);
216 this.tab
.appendText(name
);
217 this.tab
.addEvent("click", function(e
) {
219 parentObject
.selectWindow(this);
222 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
223 var tabclose
= new Element("span");
224 tabclose
.set("text", "X");
225 tabclose
.addClass("tabclose");
226 tabclose
.addEvent("click", function(e
) {
229 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
230 this.client
.exec("/PART " + name
);
235 this.tab
.appendChild(tabclose
);
238 this.lines
= new Element("div");
239 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
240 this.lines
.addClass("lines");
242 this.lines
.addEvent("scroll", function() {
243 this.scrolleddown
= this.scrolledDown();
246 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
247 this.topic
= new Element("div");
248 this.topic
.addClass("topic");
249 this.topic
.addClass("tab-invisible");
250 this.topic
.set("html", " ");
251 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
253 this.prevNick
= null;
254 this.nicklist
= new Element("div");
255 this.nicklist
.addClass("nicklist");
256 this.nicklist
.addClass("tab-invisible");
257 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
258 this.parentObject
.qjsui
.applyClasses("nicklist", this.nicklist
);
261 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
262 this.updateTopic("");
268 this.parentObject
.reflow();
270 onResize: function() {
271 if(this.scrolleddown
)
272 this.scrollToBottom();
274 createMenu: function(nick
, parent
) {
275 var e
= new Element("div");
276 parent
.appendChild(e
);
279 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
280 var e2
= new Element("a");
284 e2
.set("text", "- " + x
[0]);
286 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
287 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
[1]); }.bind(this));
291 menuClick: function(fn
) {
293 this.prevNick.removeChild(this.prevNick.menu);
294 this.prevNick.menu = null;
296 fn
.bind(this)(this.prevNick
.realNick
);
297 this.removePrevMenu();
299 moveMenuClass: function() {
302 if(this.nicklist
.firstChild
== this.prevNick
) {
303 this.prevNick
.removeClass("selected-middle");
305 this.prevNick
.addClass("selected-middle");
308 removePrevMenu: function() {
312 this.prevNick
.removeClass("selected");
313 this.prevNick
.removeClass("selected-middle");
314 if(this.prevNick
.menu
)
315 this.prevNick
.removeChild(this.prevNick
.menu
);
316 this.prevNick
= null;
318 nickListAdd: function(nick
, position
) {
319 var e
= new Element("a");
320 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
323 e
.appendChild(document
.createTextNode(nick
));
325 e
.realNick
= this.client
.stripPrefix(nick
);
327 e
.addEvent("click", function(x
) {
328 if(this.prevNick
== e
) {
329 this.removePrevMenu();
333 this.removePrevMenu();
335 e
.addClass("selected");
336 this.moveMenuClass();
337 e
.menu
= this.createMenu(x
.realNick
, e
);
340 e
.addEvent("dblclick", function(x
) {
342 this.client
.exec("/QUERY " + e
.realNick
);
345 e
.addEvent("focus", function() { this.blur() }.bind(e
));
346 this.moveMenuClass();
349 nickListRemove: function(nick
, stored
) {
350 this.nicklist
.removeChild(stored
);
351 this.moveMenuClass();
353 updateTopic: function(topic
) {
357 t
.removeChild(t
.firstChild
);
360 this.parent(topic
, t
);
362 var e
= new Element("div");
363 e
.set("text", "(no topic set)");
364 e
.addClass("emptytopic");
370 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
372 this.tab
.removeClass("tab-unselected");
373 this.tab
.addClass("tab-selected");
375 this.parentObject
.setLines(this.lines
);
376 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
377 this.parentObject
.qjsui
.showInput(inputVisible
);
378 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
));
385 this.parentObject
.inputbox
.focus();
387 deselect: function() {
390 this.tab
.removeClass("tab-selected");
391 this.tab
.addClass("tab-unselected");
396 this.parentObject
.tabs
.removeChild(this.tab
);
398 addLine: function(type
, line
, colour
) {
399 var e
= new Element("div");
402 e
.setStyles({"background": colour
});
403 } else if(this.lastcolour
) {
404 e
.addClass("linestyle1");
406 e
.addClass("linestyle2");
408 this.lastcolour
= !this.lastcolour
;
410 this.parent(type
, line
, colour
, e
);
412 setHilighted: function(state
) {
413 laststate
= this.hilighted
;
417 if(state
== laststate
)
420 this.tab
.removeClass("tab-hilight-activity");
421 this.tab
.removeClass("tab-hilight-us");
422 this.tab
.removeClass("tab-hilight-speech");
424 switch(this.hilighted
) {
425 case qwebirc
.ui
.HILIGHT_US:
426 this.tab
.addClass("tab-hilight-us");
428 case qwebirc
.ui
.HILIGHT_SPEECH:
429 this.tab
.addClass("tab-hilight-speech");
431 case qwebirc
.ui
.HILIGHT_ACTIVITY:
432 this.tab
.addClass("tab-hilight-activity");