]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/qui.js
Better URL/channel parsing.
[irc/quakenet/qwebirc.git] / js / ui / qui.js
CommitLineData
35155ba7
CP
1/* IE SUCKS */
2var BORDER_SIZE = 3;
3var INPUT_BORDER_SIZE = 2;
4var TOPIC_BORDER_SIZE = 5;
5
f4ae92cc
CP
6var QUIWindow = new Class({
7 Extends: UIWindow,
8
9 initialize: function(parentObject, client, type, name) {
10 this.parent(parentObject, client, type, name);
be0bd774 11
66de775f 12 this.tab = new Element("a", {"href": "#"});
f4ae92cc 13 this.tab.addClass("tab");
35155ba7 14 parentObject.tabs.appendChild(this.tab);
f4ae92cc
CP
15
16 this.tab.appendText(name);
66de775f
CP
17 this.tab.addEvent("click", function(e) {
18 new Event(e).stop();
f4ae92cc
CP
19 parentObject.selectWindow(this);
20 }.bind(this));
f4ae92cc
CP
21
22 if(type != WINDOW_STATUS) {
23 tabclose = new Element("span");
24 tabclose.addClass("tabclose");
25 tabclose.addEvent("click", function(e) {
26 new Event(e).stop();
27
28 if(type == WINDOW_CHANNEL)
29 this.client.exec("/PART " + name);
30
31 this.close();
32 }.bind(this));
33 tabclose.set("text", "X");
35155ba7
CP
34 if(BrowserVersion() == "ie7" || BrowserVersion() == "ie6") {
35 } else {
36 tabclose.setStyle("padding", "2px");
37 tabclose.setStyle("vertical-align", "top");
38 }
f4ae92cc
CP
39 this.tab.appendChild(tabclose);
40 }
be0bd774
CP
41
42 this.parentObject.reflow();
43
44 this.window = new Element("div");
45 this.window.addClass("window");
46 parentObject.container.appendChild(this.window);
47
48 this.lines = new Element("div");
49 this.lines.addClass("lines");
50 this.window.appendChild(this.lines);
51
52 var formdiv = new Element("div");
53 this.window.appendChild(formdiv);
359b7edd 54 this.formdiv = formdiv;
be0bd774
CP
55
56 var form = new Element("form");
57 var inputbox = new Element("input");
9b63b053 58
be0bd774
CP
59 formdiv.addClass("input");
60
61 form.addEvent("submit", function(e) {
62 new Event(e).stop();
63
9b63b053 64 this.historyExec(inputbox.value);
be0bd774
CP
65 inputbox.value = "";
66 }.bind(this));
67 formdiv.appendChild(form);
68 form.appendChild(inputbox);
69
9b63b053
CP
70 inputbox.addEvent("keypress", function(e) {
71 var result;
72 if(e.key == "up") {
73 result = this.commandhistory.nextLine();
74 } else if(e.key == "down") {
75 result = this.commandhistory.prevLine();
76 } else {
77 return;
78 }
79
80 new Event(e).stop();
81 if(!result)
82 result = ""
83 inputbox.value = result;
84 setAtEnd(inputbox);
85 }.bind(this));
25be5960 86 this.inputbox = inputbox;
35155ba7
CP
87 if(BrowserVersion() == "ie7") {
88 } else {
89 this.formdiv.setStyle("bottom", "0px");
90 }
be0bd774 91 if(type == WINDOW_CHANNEL) {
be0bd774
CP
92 this.topic = new Element("div");
93 this.topic.addClass("topic");
94 this.topic.set("html", " ");
359b7edd 95
be0bd774
CP
96 this.window.appendChild(this.topic);
97
66de775f
CP
98 this.nicklist = new Element("div");
99 this.nicklist.addClass("nicklist");
66de775f
CP
100
101 this.window.appendChild(this.nicklist);
be0bd774 102 }
be0bd774 103 this.lines.addClass("lines");
359b7edd
CP
104 if(type == WINDOW_CHANNEL) {
105 /* calls reflow */
106 this.updateTopic("");
107 } else {
108 this.reflow();
109 }
25be5960
CP
110
111 this.lines.addEvent("scroll", function() {
112 this.scrolleddown = this.scrolledDown();
113 }.bind(this));
35155ba7
CP
114 },
115 onResize: function() {
116 if(this.scrolleddown)
117 this.scrollToBottom();
118 this.reflow();
f4ae92cc 119 },
359b7edd
CP
120 reflow: function() {
121 var toppos = 0;
122 var rightpos = 0;
123 var bottompos = this.formdiv.getSize().y;
35155ba7 124 var bv = BrowserVersion();
359b7edd
CP
125
126 if(this.type == WINDOW_CHANNEL) {
127 toppos = this.topic.getSize().y;
128
129 this.nicklist.setStyle("top", toppos + "px");
130 this.nicklist.setStyle("bottom", (bottompos - 1) + "px");
2b8e1a88 131 rightpos = this.nicklist.getSize().x;
359b7edd
CP
132 }
133
134 this.lines.setStyle("top", toppos + "px");
35155ba7
CP
135
136 if(bv == "ie6") {
137 var w = this.window.getSize().x;
138 if(w == 0) {
139 this.reflow.delay(1, this);
140 return;
141 }
142 if(this.type == WINDOW_CHANNEL)
143 this.topic.setStyle("width", (w - TOPIC_BORDER_SIZE) + "px");
144 this.formdiv.setStyle("width", (w - 2 * INPUT_BORDER_SIZE) + "px");
145 this.lines.setStyle("width", (w - rightpos) + "px");
146 } else {
147 this.lines.setStyle("right", rightpos + "px");
148 }
149 /* @IESUCKS */
150 if(bv == "ie7" || bv == "ie6") {
151 var winheight = this.window.getSize().y;
152 if(winheight == 0) {
153 this.reflow.delay(1, this);
154 return;
155 }
156 this.lines.setStyle("height", (winheight - toppos - bottompos) + "px");
157 this.formdiv.setStyle("top", (winheight - bottompos) + "px");
158 if(this.type == WINDOW_CHANNEL && (bv == "ie6"))
159 this.nicklist.setStyle("height", (winheight - toppos - bottompos) + "px");
160 } else {
161 this.lines.setStyle("bottom", bottompos + "px");
162 }
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
CP
194 },
195 select: function() {
be0bd774 196 this.window.removeClass("tab-invisible");
f4ae92cc 197 this.tab.removeClass("tab-unselected");
f4ae92cc 198 this.tab.addClass("tab-selected");
359b7edd
CP
199 this.reflow();
200
7c633700 201 this.parent();
25be5960
CP
202
203 this.inputbox.focus();
f4ae92cc
CP
204 },
205 deselect: function() {
206 this.parent();
207
be0bd774 208 this.window.addClass("tab-invisible");
f4ae92cc
CP
209 this.tab.removeClass("tab-selected");
210 this.tab.addClass("tab-unselected");
211 },
212 close: function() {
213 this.parent();
214
be0bd774 215 this.parentObject.container.removeChild(this.window);
f4ae92cc
CP
216 this.parentObject.tabs.removeChild(this.tab);
217 },
218 addLine: function(type, line, colour) {
f4ae92cc
CP
219 var e = new Element("div");
220
221 if(colour) {
222 e.setStyles({"background": colour});
223 } else if(this.lastcolour) {
224 e.addClass("linestyle1");
225 } else {
226 e.addClass("linestyle2");
227 }
f4ae92cc 228 this.lastcolour = !this.lastcolour;
35155ba7 229
be0bd774
CP
230 this.parent(type, line, colour, e);
231 },
232 setHilighted: function(state) {
233 this.parent(state);
f4ae92cc 234
be0bd774 235 if(state) {
7c633700 236 this.tab.addClass("tab-hilighted");
be0bd774 237 } else {
7c633700 238 this.tab.removeClass("tab-hilighted");
be0bd774 239 }
f4ae92cc
CP
240 }
241});
242
243var QUI = new Class({
244 Extends: UI,
245 initialize: function(parentElement, theme) {
35155ba7
CP
246 if(BrowserVersion() == "ie6") {
247 if((parentElement.getStyle("top") == "0px") && (parentElement.getStyle("bottom") == "0px")) {
248 parentElement.setStyle("top", null);
249 parentElement.setStyle("height", "100%");
250 }
251 }
ba47bd8b 252 this.parent(parentElement, QUIWindow, "qui");
f4ae92cc
CP
253 this.theme = theme;
254 this.parentElement = parentElement;
255 },
be0bd774
CP
256 reflow: function() {
257 var tabheight = this.tabs.getSize().y;
35155ba7
CP
258 var bv = BrowserVersion();
259 if(bv == "ie7" || bv == "ie6")
260 tabheight = tabheight - 2 * BORDER_SIZE;
261 this.xcontainer.setStyle("top", tabheight + "px");
262 if(bv == "ie7" || bv == "ie6") {
263 this.xcontainer.setStyle("bottom", "");
264 this.xcontainer.setStyle("height", (this.parentElement.getSize().y - (tabheight)) + "px");
265 }
be0bd774
CP
266 },
267 postInitialize: function() {
268 this.outerContainer = new Element("div");
269 this.outerContainer.addClass("outercontainer");
270 this.parentElement.appendChild(this.outerContainer);
271
f4ae92cc
CP
272 this.tabs = new Element("div");
273 this.tabs.addClass("tabbar");
be0bd774 274 this.outerContainer.appendChild(this.tabs);
f4ae92cc 275
f4ae92cc
CP
276 this.container = new Element("div");
277 this.container.addClass("container");
be0bd774 278 this.outerContainer.appendChild(this.container);
35155ba7
CP
279
280 //this.container.setStyle("background", "red");
281 //this.container.setStyle("border", "1px solid black");
282
283 this.xcontainer = this.container;
284
285 //this.container = new Element("div");
286 window.addEvent("resize", function() {
287 this.reflow();
288
289 for(i=0;i<this.windowArray.length;i++)
290 this.windowArray[i].onResize();
291 }.bind(this));
f4ae92cc 292 },
66de775f 293 loginBox: function(callbackfn, intialNickname, initialChannels, autoConnect, autoNick) {
f4ae92cc
CP
294 this.parent(function(options) {
295 this.postInitialize();
296 callbackfn(options);
66de775f 297 }.bind(this), intialNickname, initialChannels, autoConnect, autoNick);
f4ae92cc
CP
298 }
299});