]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/qui.js
1 var QJSUI
= new Class({
2 initialize: function(class_
, parent
, sizer
) {
4 this.sizer
= $defined(sizer
)?sizer:parent
;
9 this.reflowevent
= null;
11 window
.addEvent("resize", function() {
15 applyClasses: function(pos
, l
) {
16 l
.addClass("dynamicpanel");
17 l
.addClass(this.class_
);
20 l
.addClass("leftboundpanel");
21 } else if(pos
== "top") {
22 l
.addClass("topboundpanel");
23 l
.addClass("widepanel");
24 } else if(pos
== "topic") {
25 l
.addClass("widepanel");
26 } else if(pos
== "right") {
27 l
.addClass("rightboundpanel");
28 } else if(pos
== "bottom") {
29 l
.addClass("bottomboundpanel");
30 l
.addClass("widepanel");
34 var XE = function(pos
) {
35 var element
= new Element("div");
36 this.applyClasses(pos
, element
);
38 this.parent
.appendChild(element
);
43 this.topic
= XE("topic");
44 this.middle
= XE("middle");
45 this.right
= XE("right");
46 this.bottom
= XE("bottom");
48 reflow: function(delay
) {
53 $clear(this.reflowevent
);
55 this.reflowevent
= this.__reflow
.delay(delay
, this);
57 __reflow: function() {
58 var bottom
= this.bottom
;
59 var middle
= this.middle
;
60 var right
= this.right
;
61 var topic
= this.topic
;
64 var topicsize
= topic
.getSize();
65 var topsize
= top
.getSize();
66 var rightsize
= right
.getSize();
67 var bottomsize
= bottom
.getSize();
68 var docsize
= this.sizer
.getSize();
70 var mheight
= (docsize
.y
- topsize
.y
- bottomsize
.y
- topicsize
.y
);
71 var mwidth
= (docsize
.x
- rightsize
.x
);
73 topic
.setStyle("top", topsize
.y
+ "px");
75 middle
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
77 middle
.setStyle("height", mheight
+ "px");
78 right
.setStyle("height", mheight
+ "px");
82 middle
.setStyle("width", mwidth
+ "px");
83 right
.setStyle("top", (topsize
.y
+ topicsize
.y
) + "px");
84 right
.setStyle("left", mwidth
+ "px");
86 bottom
.setStyle("top", (docsize
.y
- bottomsize
.y
) + "px");
88 showChannel: function(state
) {
93 this.right
.setStyle("display", display
);
94 this.topic
.setStyle("display", display
);
96 showInput: function(state
) {
97 this.bottom
.setStyle("display", state
?"block":"none");
101 var QUIWindow
= new Class({
104 initialize: function(parentObject
, client
, type
, name
) {
105 this.parent(parentObject
, client
, type
, name
);
107 this.tab
= new Element("a", {"href": "#"});
108 this.tab
.addClass("tab");
109 parentObject
.tabs
.appendChild(this.tab
);
111 this.tab
.appendText(name
);
112 this.tab
.addEvent("click", function(e
) {
114 parentObject
.selectWindow(this);
117 if(type
!= WINDOW_STATUS
&& type
!= WINDOW_CONNECT
) {
118 tabclose
= new Element("span");
119 tabclose
.addClass("tabclose");
120 tabclose
.addEvent("click", function(e
) {
123 if(type
== WINDOW_CHANNEL
)
124 this.client
.exec("/PART " + name
);
129 this.tab
.appendChild(tabclose
);
132 this.lines
= new Element("div");
133 this.parentObject
.qjsui
.applyClasses("middle", this.lines
);
134 this.lines
.addClass("lines");
136 this.lines
.addEvent("scroll", function() {
137 this.scrolleddown
= this.scrolledDown();
140 if(type
== WINDOW_CHANNEL
) {
141 this.topic
= new Element("div");
142 this.topic
.addClass("topic");
143 this.topic
.addClass("tab-invisible");
144 this.topic
.set("html", " ");
145 this.parentObject
.qjsui
.applyClasses("topic", this.topic
);
147 this.nicklist
= new Element("div");
148 this.nicklist
.addClass("nicklist");
149 this.nicklist
.addClass("tab-invisible");
150 this.parentObject
.qjsui
.applyClasses("nicklist", this.nicklist
);
153 if(type
== WINDOW_CHANNEL
) {
154 this.updateTopic("");
160 this.parentObject
.reflow();
162 onResize: function() {
163 if(this.scrolleddown
)
164 this.scrollToBottom();
166 updateNickList: function(nicks
) {
169 var n
= this.nicklist
;
171 n
.removeChild(n
.firstChild
);
173 nicks
.each(function(nick
) {
174 var e
= new Element("div");
176 e
.appendChild(document
.createTextNode(nick
));
179 updateTopic: function(topic
) {
185 t
.removeChild(t
.firstChild
);
188 Colourise("[" + topic
+ "]", t
);
190 var e
= new Element("div");
191 e
.set("text", "(no topic set)");
192 e
.addClass("emptytopic");
198 var inputVisible
= this.type
!= WINDOW_CONNECT
&& this.type
!= WINDOW_CUSTOM
;
200 this.tab
.removeClass("tab-unselected");
201 this.tab
.addClass("tab-selected");
203 this.parentObject
.setLines(this.lines
);
204 this.parentObject
.setChannelItems(this.nicklist
, this.topic
);
205 this.parentObject
.qjsui
.showInput(inputVisible
);
206 this.parentObject
.qjsui
.showChannel($defined(this.nicklist
));
213 this.parentObject
.inputbox
.focus();
215 deselect: function() {
218 this.tab
.removeClass("tab-selected");
219 this.tab
.addClass("tab-unselected");
224 this.parentObject
.tabs
.removeChild(this.tab
);
226 addLine: function(type
, line
, colour
) {
227 var e
= new Element("div");
230 e
.setStyles({"background": colour
});
231 } else if(this.lastcolour
) {
232 e
.addClass("linestyle1");
234 e
.addClass("linestyle2");
236 this.lastcolour
= !this.lastcolour
;
238 this.parent(type
, line
, colour
, e
);
240 setHilighted: function(state
) {
244 this.tab
.addClass("tab-hilighted");
246 this.tab
.removeClass("tab-hilighted");
251 var QUI
= new Class({
253 initialize: function(parentElement
, theme
) {
254 this.parent(parentElement
, QUIWindow
, "qui");
256 this.parentElement
= parentElement
;
258 postInitialize: function() {
259 this.qjsui
= new QJSUI("qwebirc-qui", this.parentElement
);
261 this.qjsui
.top
.addClass("tabbar");
263 this.qjsui
.bottom
.addClass("input");
264 this.qjsui
.right
.addClass("nicklist");
265 this.qjsui
.topic
.addClass("topic");
266 this.qjsui
.middle
.addClass("lines");
268 this.tabs
= this.qjsui
.top
;
269 this.origtopic
= this.topic
= this.qjsui
.topic
;
270 this.origlines
= this.lines
= this.qjsui
.middle
;
271 this.orignicklist
= this.nicklist
= this.qjsui
.right
;
273 this.input
= this.qjsui
.bottom
;
274 this.reflow
= this.qjsui
.reflow
.bind(this.qjsui
);
279 createInput: function() {
280 var form
= new Element("form");
281 this.input
.appendChild(form
);
282 form
.addClass("input");
284 var inputbox
= new Element("input");
285 form
.appendChild(inputbox
);
286 this.inputbox
= inputbox
;
288 form
.addEvent("submit", function(e
) {
291 if(inputbox
.value
== "")
294 this.getActiveWindow().historyExec(inputbox
.value
);
298 inputbox
.addEvent("keydown", function(e
) {
300 var cvalue
= inputbox
.value
;
303 resultfn
= this.commandhistory
.upLine
;
304 } else if(e
.key
== "down") {
305 resultfn
= this.commandhistory
.downLine
;
310 if((cvalue
!= "") && (this.lastcvalue
!= cvalue
))
311 this.commandhistory
.addLine(cvalue
, true);
313 var result
= resultfn
.bind(this.commandhistory
)();
318 this.lastcvalue
= result
;
320 inputbox
.value
= result
;
324 setLines: function(lines
) {
325 this.lines
.parentNode
.replaceChild(lines
, this.lines
);
326 this.qjsui
.middle
= this.lines
= lines
;
328 setChannelItems: function(nicklist
, topic
) {
329 if(!$defined(nicklist
)) {
330 nicklist
= this.orignicklist
;
331 topic
= this.origtopic
;
333 this.nicklist
.parentNode
.replaceChild(nicklist
, this.nicklist
);
334 this.qjsui
.right
= this.nicklist
= nicklist
;
336 this.topic
.parentNode
.replaceChild(topic
, this.topic
);
337 this.qjsui
.topic
= this.topic
= topic
;