]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/qui.js
Whoops.
[irc/quakenet/qwebirc.git] / js / ui / qui.js
CommitLineData
b1ee83f3
CP
1var QJSUI = new Class({
2 initialize: function(class_, parent, sizer) {
3 this.parent = parent;
4 this.sizer = $defined(sizer)?sizer:parent;
5
24ede2cb
CP
6 this.class_ = class_;
7 this.create();
8
b1ee83f3
CP
9 window.addEvent("resize", function() {
10 this.reflow();
11 this.reflow.delay(100, this);
12 }.bind(this));
13 },
24ede2cb
CP
14 applyClasses: function(pos, l) {
15 l.addClass("dynamicpanel");
16
17 l.addClass(this.class_);
18 if(pos == "middle") {
19 l.addClass("leftboundpanel");
20 } else if(pos == "top") {
21 l.addClass("topboundpanel");
22 l.addClass("widepanel");
23 } else if(pos == "topic") {
24 l.addClass("widepanel");
25 } else if(pos == "right") {
26 l.addClass("rightboundpanel");
27 } else if(pos == "bottom") {
28 l.addClass("bottomboundpanel");
29 l.addClass("widepanel");
30 }
31 },
32 create: function() {
33 var XE = function(pos) {
34 var element = new Element("div");
35 this.applyClasses(pos, element);
b1ee83f3 36
24ede2cb
CP
37 this.parent.appendChild(element);
38 return element;
b1ee83f3
CP
39 }.bind(this);
40
24ede2cb
CP
41 this.top = XE("top");
42 this.topic = XE("topic");
43 this.middle = XE("middle");
44 this.right = XE("right");
45 this.bottom = XE("bottom");
b1ee83f3
CP
46 },
47 reflow: function() {
48 var bottom = this.bottom;
49 var middle = this.middle;
50 var right = this.right;
51 var topic = this.topic;
52 var top = this.top;
53
54 var topicsize = topic.getSize();
55 var topsize = top.getSize();
56 var rightsize = right.getSize();
57 var bottomsize = bottom.getSize();
58 var docsize = this.sizer.getSize();
59
60 var mheight = (docsize.y - topsize.y - bottomsize.y - topicsize.y);
61 var mwidth = (docsize.x - rightsize.x);
62
63 topic.setStyle("top", topsize.y + "px");
64
65 middle.setStyle("top", (topsize.y + topicsize.y) + "px");
66 if(mheight > 0) {
67 middle.setStyle("height", mheight + "px");
68 right.setStyle("height", mheight + "px");
69 }
70
71 if(mwidth > 0) {
72 middle.setStyle("width", mwidth + "px");
73 } else {
74 alert(mwidth);
75 }
76 right.setStyle("top", (topsize.y + topicsize.y) + "px");
77 right.setStyle("left", mwidth + "px");
78
79 bottom.setStyle("top", (docsize.y - bottomsize.y) + "px");
80 },
81 showChannel: function(state) {
82 var display = "none";
83 if(state)
84 display = "block";
85
86 this.right.setStyle("display", display);
87 this.topic.setStyle("display", display);
88 //this.reflow.delay(0, this);
89 }
90});
35155ba7 91
f4ae92cc
CP
92var QUIWindow = new Class({
93 Extends: UIWindow,
94
95 initialize: function(parentObject, client, type, name) {
96 this.parent(parentObject, client, type, name);
be0bd774 97
66de775f 98 this.tab = new Element("a", {"href": "#"});
f4ae92cc 99 this.tab.addClass("tab");
35155ba7 100 parentObject.tabs.appendChild(this.tab);
f4ae92cc
CP
101
102 this.tab.appendText(name);
66de775f
CP
103 this.tab.addEvent("click", function(e) {
104 new Event(e).stop();
f4ae92cc
CP
105 parentObject.selectWindow(this);
106 }.bind(this));
f4ae92cc
CP
107
108 if(type != WINDOW_STATUS) {
109 tabclose = new Element("span");
110 tabclose.addClass("tabclose");
111 tabclose.addEvent("click", function(e) {
112 new Event(e).stop();
113
114 if(type == WINDOW_CHANNEL)
115 this.client.exec("/PART " + name);
116
117 this.close();
118 }.bind(this));
119 tabclose.set("text", "X");
35155ba7
CP
120 if(BrowserVersion() == "ie7" || BrowserVersion() == "ie6") {
121 } else {
122 tabclose.setStyle("padding", "2px");
123 tabclose.setStyle("vertical-align", "top");
124 }
f4ae92cc
CP
125 this.tab.appendChild(tabclose);
126 }
be0bd774 127
be0bd774 128 this.lines = new Element("div");
24ede2cb
CP
129 //this.parentObject.qjsui.applyClasses("middle", lines);
130
be0bd774 131 this.lines.addClass("lines");
b1ee83f3
CP
132 this.lines.addClass("tab-invisible");
133 parentObject.lines.appendChild(this.lines);
134 this.lines.addEvent("scroll", function() {
135 this.scrolleddown = this.scrolledDown();
be0bd774 136 }.bind(this));
be0bd774 137
be0bd774 138 if(type == WINDOW_CHANNEL) {
be0bd774
CP
139 this.topic = new Element("div");
140 this.topic.addClass("topic");
b1ee83f3 141 this.topic.addClass("tab-invisible");
be0bd774 142 this.topic.set("html", " ");
b1ee83f3 143 parentObject.topic.appendChild(this.topic);
be0bd774 144
66de775f
CP
145 this.nicklist = new Element("div");
146 this.nicklist.addClass("nicklist");
b1ee83f3
CP
147 this.nicklist.addClass("tab-invisible");
148 parentObject.nicklist.appendChild(this.nicklist);
be0bd774 149 }
b1ee83f3 150
359b7edd 151 if(type == WINDOW_CHANNEL) {
359b7edd
CP
152 this.updateTopic("");
153 } else {
154 this.reflow();
155 }
b1ee83f3
CP
156 },
157 reflow: function() {
158 this.parentObject.reflow();
35155ba7
CP
159 },
160 onResize: function() {
161 if(this.scrolleddown)
162 this.scrollToBottom();
359b7edd 163 },
f4ae92cc
CP
164 updateNickList: function(nicks) {
165 this.parent(nicks);
166
167 var n = this.nicklist;
168 while(n.firstChild)
169 n.removeChild(n.firstChild);
170
171 nicks.each(function(nick) {
172 var e = new Element("div");
173 n.appendChild(e);
174 e.appendChild(document.createTextNode(nick));
175 });
176 },
177 updateTopic: function(topic) {
178 this.parent(topic);
179
180 var t = this.topic;
181
182 while(t.firstChild)
183 t.removeChild(t.firstChild);
184
66de775f 185 if(topic) {
359b7edd 186 Colourise("[" + topic + "]", t);
66de775f 187 } else {
359b7edd
CP
188 var e = new Element("div");
189 e.set("text", "(no topic set)");
66de775f 190 e.addClass("emptytopic");
359b7edd 191 t.appendChild(e);
66de775f 192 }
359b7edd 193 this.reflow();
f4ae92cc 194 },
b1ee83f3
CP
195 showChannel: function() {
196 this.parentObject.qjsui.showChannel($defined(this.nicklist));
197 this.reflow();
198 },
f4ae92cc 199 select: function() {
f4ae92cc 200 this.tab.removeClass("tab-unselected");
f4ae92cc 201 this.tab.addClass("tab-selected");
359b7edd 202
24ede2cb
CP
203 //this.parentObject.lines.parentNode.replaceChild(this.parentObject.lines, this.lines);
204
b1ee83f3
CP
205 this.lines.removeClass("tab-invisible");
206 if(this.nicklist) {
207 this.nicklist.removeClass("tab-invisible");
208 this.topic.removeClass("tab-invisible");
209 }
210 this.showChannel();
7c633700 211 this.parent();
25be5960 212
b1ee83f3 213 this.parentObject.inputbox.focus();
f4ae92cc
CP
214 },
215 deselect: function() {
216 this.parent();
217
b1ee83f3
CP
218 this.lines.addClass("tab-invisible");
219 if(this.nicklist) {
220 this.nicklist.addClass("tab-invisible");
221 this.topic.addClass("tab-invisible");
222 }
f4ae92cc
CP
223 this.tab.removeClass("tab-selected");
224 this.tab.addClass("tab-unselected");
b1ee83f3
CP
225
226 //this.showChannel();
f4ae92cc
CP
227 },
228 close: function() {
229 this.parent();
230
b1ee83f3
CP
231 this.parentObject.lines.removeChild(this.lines);
232 if(this.nicklist) {
233 this.parentObject.nicklist.removeChild(this.nicklist);
234 this.parentObject.topic.removeChild(this.topic);
235 }
f4ae92cc
CP
236 this.parentObject.tabs.removeChild(this.tab);
237 },
238 addLine: function(type, line, colour) {
f4ae92cc
CP
239 var e = new Element("div");
240
241 if(colour) {
242 e.setStyles({"background": colour});
243 } else if(this.lastcolour) {
244 e.addClass("linestyle1");
245 } else {
246 e.addClass("linestyle2");
247 }
f4ae92cc 248 this.lastcolour = !this.lastcolour;
35155ba7 249
be0bd774
CP
250 this.parent(type, line, colour, e);
251 },
252 setHilighted: function(state) {
253 this.parent(state);
f4ae92cc 254
be0bd774 255 if(state) {
7c633700 256 this.tab.addClass("tab-hilighted");
be0bd774 257 } else {
7c633700 258 this.tab.removeClass("tab-hilighted");
be0bd774 259 }
f4ae92cc
CP
260 }
261});
262
263var QUI = new Class({
264 Extends: UI,
265 initialize: function(parentElement, theme) {
ba47bd8b 266 this.parent(parentElement, QUIWindow, "qui");
f4ae92cc
CP
267 this.theme = theme;
268 this.parentElement = parentElement;
269 },
be0bd774 270 reflow: function() {
b1ee83f3
CP
271 //alert("REFLOW");
272 this.qjsui.reflow();
be0bd774
CP
273 },
274 postInitialize: function() {
b1ee83f3 275 this.qjsui = new QJSUI("qwebirc-qui", this.parentElement, document);
f4ae92cc 276
b1ee83f3 277 this.qjsui.top.addClass("tabbar");
35155ba7 278
b1ee83f3
CP
279 this.qjsui.bottom.addClass("input");
280 this.qjsui.right.addClass("nicklist");
281 this.qjsui.topic.addClass("topic");
282 this.qjsui.middle.addClass("lines");
35155ba7 283
b1ee83f3
CP
284 this.tabs = this.qjsui.top;
285 this.topic = this.qjsui.topic;
286 this.lines = this.qjsui.middle;
287 this.nicklist = this.qjsui.right;
288 this.input = this.qjsui.bottom;
289 this.createInput();
290 this.reflow();
291 },
292 createInput: function() {
293 var form = new Element("form");
294 this.input.appendChild(form);
295 form.addClass("input");
35155ba7 296
b1ee83f3
CP
297 var inputbox = new Element("input");
298 form.appendChild(inputbox);
299 this.inputbox = inputbox;
300
301 form.addEvent("submit", function(e) {
302 new Event(e).stop();
303
304 if(inputbox.value == "")
305 return;
306
307 this.getActiveWindow().historyExec(inputbox.value);
308 inputbox.value = "";
309 }.bind(this));
310
311 inputbox.addEvent("keydown", function(e) {
312 var resultfn;
313 var cvalue = inputbox.value;
314
315 if(e.key == "up") {
316 resultfn = this.commandhistory.upLine;
317 } else if(e.key == "down") {
318 resultfn = this.commandhistory.downLine;
319 } else {
320 return;
321 }
35155ba7 322
b1ee83f3
CP
323 if((cvalue != "") && (this.lastcvalue != cvalue))
324 this.commandhistory.addLine(cvalue, true);
325
326 var result = resultfn.bind(this.commandhistory)();
327
328 new Event(e).stop();
329 if(!result)
330 result = "";
331 this.lastcvalue = result;
332
333 inputbox.value = result;
334 setAtEnd(inputbox);
35155ba7 335 }.bind(this));
f4ae92cc 336 },
66de775f 337 loginBox: function(callbackfn, intialNickname, initialChannels, autoConnect, autoNick) {
f4ae92cc
CP
338 this.parent(function(options) {
339 this.postInitialize();
340 callbackfn(options);
66de775f 341 }.bind(this), intialNickname, initialChannels, autoConnect, autoNick);
f4ae92cc
CP
342 }
343});