]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/qui.js
2c1a95506a70bb6fc7e872c3adae0d54e646aa34
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
);
29 createInput: function() {
30 var form
= new Element("form");
31 this.input
.appendChild(form
);
32 form
.addClass("input");
34 var inputbox
= new Element("input");
35 form
.appendChild(inputbox
);
36 this.inputbox
= inputbox
;
38 form
.addEvent("submit", function(e
) {
41 if(inputbox
.value
== "")
44 this.getActiveWindow().historyExec(inputbox
.value
);
48 inputbox
.addEvent("keydown", function(e
) {
50 var cvalue
= inputbox
.value
;
53 resultfn
= this.commandhistory
.upLine
;
54 } else if(e
.key
== "down") {
55 resultfn
= this.commandhistory
.downLine
;
60 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
61 this.commandhistory
.addLine(cvalue
, true);
63 var result
= resultfn
.bind(this.commandhistory
)();
68 this.lastcvalue
= result
;
70 inputbox
.value
= result
;
71 qwebirc
.util
.setAtEnd(inputbox
);
74 setLines: function(lines
) {
75 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
76 this.qjsui
.middle
= this.lines
= lines
;
78 setChannelItems: function(nicklist
, topic
) {
79 if(!$defined(nicklist
)) {
80 nicklist
= this.orignicklist
;
81 topic
= this.origtopic
;
83 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
84 this.qjsui
.right
= this.nicklist
= nicklist
;
86 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
87 this.qjsui
.topic
= this.topic
= topic
;
91 qwebirc
.ui
.QUI
.JSUI
= new Class({
92 initialize: function(class_
, parent
, sizer
) {
94 this.sizer
= $defined(sizer
)?sizer:parent
;
99 this.reflowevent
= null;
101 window
.addEvent("resize", function() {
105 applyClasses: function(pos
, l
) {
106 l
.addClass("dynamicpanel");
107 l
.addClass(this.class_
);
109 if(pos
== "middle") {
110 l
.addClass("leftboundpanel");
111 } else if(pos
== "top") {
112 l
.addClass("topboundpanel");
113 l
.addClass("widepanel");
114 } else if(pos
== "topic") {
115 l
.addClass("widepanel");
116 } else if(pos
== "right") {
117 l
.addClass("rightboundpanel");
118 } else if(pos
== "bottom") {
119 l
.addClass("bottomboundpanel");
120 l
.addClass("widepanel");
124 var XE = function(pos
) {
125 var element
= new Element("div");
126 this.applyClasses(pos
, element
);
128 this.parent
.appendChild(element
);
132 this.top
= XE("top");
133 this.topic
= XE("topic");
134 this.middle
= XE("middle");
135 this.right
= XE("right");
136 this.bottom
= XE("bottom");
138 reflow: function(delay
) {
143 $clear(this.reflowevent
);
145 this.reflowevent
= this.__reflow
.delay(delay
, this);
147 __reflow: function() {
148 var bottom
= this.bottom
;
149 var middle
= this.middle
;
150 var right
= this.right
;
151 var topic
= this.topic
;
154 var topicsize
= topic
.getSize();
155 var topsize
= top
.getSize();
156 var rightsize
= right
.getSize();
157 var bottomsize
= bottom
.getSize();
158 var docsize
= this.sizer
.getSize();
160 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
161 var mwidth
= (docsize
.x
- rightsize
.x
);
163 topic
.setStyle("top", topsize
.y
+ "px");
165 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
167 middle
.setStyle("height", mheight
+ "px");
168 right
.setStyle("height", mheight
+ "px");
172 middle
.setStyle("width", mwidth
+ "px");
173 right
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
174 right
.setStyle("left", mwidth
+ "px");
176 bottom
.setStyle("top", (docsize
.y
- bottomsize
.y
) + "px");
178 showChannel: function(state
) {
179 var display
= "none";
183 this.right
.setStyle("display", display
);
184 this.topic
.setStyle("display", display
);
186 showInput: function(state
) {
187 this.bottom
.setStyle("display", state
?"block":"none");
191 qwebirc
.ui
.QUI
.Window
= new Class({
192 Extends: qwebirc
.ui
.Window
,
194 initialize: function(parentObject
, client
, type
, name
) {
195 this.parent(parentObject
, client
, type
, name
);
197 this.tab
= new Element("a", {"href": "#"});
198 this.tab
.addClass("tab");
199 this.tab
.addEvent("focus", function() { this.blur() }.bind(this.tab
));;
201 parentObject
.tabs
.appendChild(this.tab
);
203 this.tab
.appendText(name
);
204 this.tab
.addEvent("click", function(e
) {
206 parentObject
.selectWindow(this);
209 if(type
!= qwebirc
.ui
.WINDOW_STATUS
&& type
!= qwebirc
.ui
.WINDOW_CONNECT
) {
210 var tabclose
= new Element("span");
211 tabclose
.set("text", "X");
212 tabclose
.addClass("tabclose");
213 tabclose
.addEvent("click", function(e
) {
216 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
)
217 this.client
.exec("/PART " + name
);
222 this.tab
.appendChild(tabclose
);
225 this.lines
= new Element("div");
226 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
227 this.lines
.addClass("lines");
229 this.lines
.addEvent("scroll", function() {
230 this.scrolleddown
= this.scrolledDown();
233 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
234 this.topic
= new Element("div");
235 this.topic
.addClass("topic");
236 this.topic
.addClass("tab-invisible");
237 this.topic
.set("html", " ");
238 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
240 this.prevNick
= null;
241 this.nicklist
= new Element("div");
242 this.nicklist
.addClass("nicklist");
243 this.nicklist
.addClass("tab-invisible");
244 this.nicklist
.addEvent("click", this.removePrevMenu
.bind(this));
245 this.parentObject
.qjsui
.applyClasses("nicklist", this.nicklist
);
248 if(type
== qwebirc
.ui
.WINDOW_CHANNEL
) {
249 this.updateTopic("");
255 this.parentObject
.reflow();
257 onResize: function() {
258 if(this.scrolleddown
)
259 this.scrollToBottom();
261 createMenu: function(nick
, parent
) {
262 var e
= new Element("div");
263 parent
.appendChild(e
);
266 qwebirc
.ui
.MENU_ITEMS
.forEach(function(x
) {
267 var e2
= new Element("a");
271 e2
.set("text", "- " + x
[0]);
273 e2
.addEvent("focus", function() { this.blur() }.bind(e2
));
274 e2
.addEvent("click", function(ev
) { new Event(ev
.stop()); this.menuClick(x
[1]); }.bind(this));
278 menuClick: function(fn
) {
280 this.prevNick.removeChild(this.prevNick.menu);
281 this.prevNick.menu = null;
283 fn
.bind(this)(this.prevNick
.realNick
);
284 this.removePrevMenu();
286 moveMenuClass: function() {
289 if(this.nicklist
.firstChild
== this.prevNick
) {
290 this.prevNick
.removeClass("selected-middle");
292 this.prevNick
.addClass("selected-middle");
295 removePrevMenu: function() {
299 this.prevNick
.removeClass("selected");
300 this.prevNick
.removeClass("selected-middle");
301 if(this.prevNick
.menu
)
302 this.prevNick
.removeChild(this.prevNick
.menu
);
303 this.prevNick
= null;
305 nickListAdd: function(nick
, position
) {
306 var e
= new Element("a");
307 qwebirc
.ui
.insertAt(position
, this.nicklist
, e
);
310 e
.appendChild(document
.createTextNode(nick
));
312 e
.realNick
= this.client
.stripPrefix(nick
);
314 e
.addEvent("click", function(x
) {
315 if(this.prevNick
== e
) {
316 this.removePrevMenu();
320 this.removePrevMenu();
322 e
.addClass("selected");
323 this.moveMenuClass();
324 e
.menu
= this.createMenu(x
.realNick
, e
);
327 e
.addEvent("dblclick", function(x
) {
329 this.client
.exec("/QUERY " + e
.realNick
);
332 e
.addEvent("focus", function() { this.blur() }.bind(e
));
333 this.moveMenuClass();
336 nickListRemove: function(nick
, stored
) {
337 this.nicklist
.removeChild(stored
);
338 this.moveMenuClass();
340 updateTopic: function(topic
) {
344 t
.removeChild(t
.firstChild
);
347 this.parent(topic
, t
);
349 var e
= new Element("div");
350 e
.set("text", "(no topic set)");
351 e
.addClass("emptytopic");
357 var inputVisible
= this.type
!= qwebirc
.ui
.WINDOW_CONNECT
&& this.type
!= qwebirc
.ui
.WINDOW_CUSTOM
;
359 this.tab
.removeClass("tab-unselected");
360 this.tab
.addClass("tab-selected");
362 this.parentObject
.setLines(this.lines
);
363 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
364 this.parentObject
.qjsui
.showInput(inputVisible
);
365 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
));
372 this.parentObject
.inputbox
.focus();
374 deselect: function() {
377 this.tab
.removeClass("tab-selected");
378 this.tab
.addClass("tab-unselected");
383 this.parentObject
.tabs
.removeChild(this.tab
);
385 addLine: function(type
, line
, colour
) {
386 var e
= new Element("div");
389 e
.setStyles({"background": colour
});
390 } else if(this.lastcolour
) {
391 e
.addClass("linestyle1");
393 e
.addClass("linestyle2");
395 this.lastcolour
= !this.lastcolour
;
397 this.parent(type
, line
, colour
, e
);
399 setHilighted: function(state
) {
400 laststate
= this.hilighted
;
404 if(state
== laststate
)
407 this.tab
.removeClass("tab-hilight-activity");
408 this.tab
.removeClass("tab-hilight-us");
409 this.tab
.removeClass("tab-hilight-speech");
411 switch(this.hilighted
) {
412 case qwebirc
.ui
.HILIGHT_US:
413 this.tab
.addClass("tab-hilight-us");
415 case qwebirc
.ui
.HILIGHT_SPEECH:
416 this.tab
.addClass("tab-hilight-speech");
418 case qwebirc
.ui
.HILIGHT_ACTIVITY:
419 this.tab
.addClass("tab-hilight-activity");