]>
Commit | Line | Data |
---|---|---|
1 | /* IE SUCKS */ | |
2 | var BORDER_SIZE = 3; | |
3 | var INPUT_BORDER_SIZE = 2; | |
4 | var TOPIC_BORDER_SIZE = 5; | |
5 | ||
6 | var QUIWindow = new Class({ | |
7 | Extends: UIWindow, | |
8 | ||
9 | initialize: function(parentObject, client, type, name) { | |
10 | this.parent(parentObject, client, type, name); | |
11 | ||
12 | this.tab = new Element("a", {"href": "#"}); | |
13 | this.tab.addClass("tab"); | |
14 | parentObject.tabs.appendChild(this.tab); | |
15 | ||
16 | this.tab.appendText(name); | |
17 | this.tab.addEvent("click", function(e) { | |
18 | new Event(e).stop(); | |
19 | parentObject.selectWindow(this); | |
20 | }.bind(this)); | |
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"); | |
34 | if(BrowserVersion() == "ie7" || BrowserVersion() == "ie6") { | |
35 | } else { | |
36 | tabclose.setStyle("padding", "2px"); | |
37 | tabclose.setStyle("vertical-align", "top"); | |
38 | } | |
39 | this.tab.appendChild(tabclose); | |
40 | } | |
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); | |
54 | this.formdiv = formdiv; | |
55 | ||
56 | var form = new Element("form"); | |
57 | var inputbox = new Element("input"); | |
58 | ||
59 | formdiv.addClass("input"); | |
60 | ||
61 | form.addEvent("submit", function(e) { | |
62 | new Event(e).stop(); | |
63 | ||
64 | this.historyExec(inputbox.value); | |
65 | inputbox.value = ""; | |
66 | }.bind(this)); | |
67 | formdiv.appendChild(form); | |
68 | form.appendChild(inputbox); | |
69 | ||
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)); | |
86 | this.inputbox = inputbox; | |
87 | if(BrowserVersion() == "ie7") { | |
88 | } else { | |
89 | this.formdiv.setStyle("bottom", "0px"); | |
90 | } | |
91 | if(type == WINDOW_CHANNEL) { | |
92 | this.topic = new Element("div"); | |
93 | this.topic.addClass("topic"); | |
94 | this.topic.set("html", " "); | |
95 | ||
96 | this.window.appendChild(this.topic); | |
97 | ||
98 | this.nicklist = new Element("div"); | |
99 | this.nicklist.addClass("nicklist"); | |
100 | ||
101 | this.window.appendChild(this.nicklist); | |
102 | } | |
103 | this.lines.addClass("lines"); | |
104 | if(type == WINDOW_CHANNEL) { | |
105 | /* calls reflow */ | |
106 | this.updateTopic(""); | |
107 | } else { | |
108 | this.reflow(); | |
109 | } | |
110 | ||
111 | this.lines.addEvent("scroll", function() { | |
112 | this.scrolleddown = this.scrolledDown(); | |
113 | }.bind(this)); | |
114 | }, | |
115 | onResize: function() { | |
116 | if(this.scrolleddown) | |
117 | this.scrollToBottom(); | |
118 | this.reflow(); | |
119 | }, | |
120 | reflow: function() { | |
121 | var toppos = 0; | |
122 | var rightpos = 0; | |
123 | var bottompos = this.formdiv.getSize().y; | |
124 | var bv = BrowserVersion(); | |
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"); | |
131 | rightpos = this.nicklist.getSize().x; | |
132 | } | |
133 | ||
134 | this.lines.setStyle("top", toppos + "px"); | |
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 | } | |
163 | }, | |
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 | ||
185 | if(topic) { | |
186 | Colourise("[" + topic + "]", t); | |
187 | } else { | |
188 | var e = new Element("div"); | |
189 | e.set("text", "(no topic set)"); | |
190 | e.addClass("emptytopic"); | |
191 | t.appendChild(e); | |
192 | } | |
193 | this.reflow(); | |
194 | }, | |
195 | select: function() { | |
196 | this.window.removeClass("tab-invisible"); | |
197 | this.tab.removeClass("tab-unselected"); | |
198 | this.tab.addClass("tab-selected"); | |
199 | this.reflow(); | |
200 | ||
201 | this.parent(); | |
202 | ||
203 | this.inputbox.focus(); | |
204 | }, | |
205 | deselect: function() { | |
206 | this.parent(); | |
207 | ||
208 | this.window.addClass("tab-invisible"); | |
209 | this.tab.removeClass("tab-selected"); | |
210 | this.tab.addClass("tab-unselected"); | |
211 | }, | |
212 | close: function() { | |
213 | this.parent(); | |
214 | ||
215 | this.parentObject.container.removeChild(this.window); | |
216 | this.parentObject.tabs.removeChild(this.tab); | |
217 | }, | |
218 | addLine: function(type, line, colour) { | |
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 | } | |
228 | this.lastcolour = !this.lastcolour; | |
229 | ||
230 | this.parent(type, line, colour, e); | |
231 | }, | |
232 | setHilighted: function(state) { | |
233 | this.parent(state); | |
234 | ||
235 | if(state) { | |
236 | this.tab.addClass("tab-hilighted"); | |
237 | } else { | |
238 | this.tab.removeClass("tab-hilighted"); | |
239 | } | |
240 | } | |
241 | }); | |
242 | ||
243 | var QUI = new Class({ | |
244 | Extends: UI, | |
245 | initialize: function(parentElement, theme) { | |
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 | } | |
252 | this.parent(parentElement, QUIWindow, "qui"); | |
253 | this.theme = theme; | |
254 | this.parentElement = parentElement; | |
255 | }, | |
256 | reflow: function() { | |
257 | var tabheight = this.tabs.getSize().y; | |
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 | } | |
266 | }, | |
267 | postInitialize: function() { | |
268 | this.outerContainer = new Element("div"); | |
269 | this.outerContainer.addClass("outercontainer"); | |
270 | this.parentElement.appendChild(this.outerContainer); | |
271 | ||
272 | this.tabs = new Element("div"); | |
273 | this.tabs.addClass("tabbar"); | |
274 | this.outerContainer.appendChild(this.tabs); | |
275 | ||
276 | this.container = new Element("div"); | |
277 | this.container.addClass("container"); | |
278 | this.outerContainer.appendChild(this.container); | |
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)); | |
292 | }, | |
293 | loginBox: function(callbackfn, intialNickname, initialChannels, autoConnect, autoNick) { | |
294 | this.parent(function(options) { | |
295 | this.postInitialize(); | |
296 | callbackfn(options); | |
297 | }.bind(this), intialNickname, initialChannels, autoConnect, autoNick); | |
298 | } | |
299 | }); |