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