]>
Commit | Line | Data |
---|---|---|
1 | qwebirc.ui.WINDOW_STATUS = 1; | |
2 | qwebirc.ui.WINDOW_QUERY = 2; | |
3 | qwebirc.ui.WINDOW_CHANNEL = 3; | |
4 | qwebirc.ui.WINDOW_CUSTOM = 4; | |
5 | qwebirc.ui.WINDOW_CONNECT = 5; | |
6 | qwebirc.ui.WINDOW_MESSAGES = 6; | |
7 | qwebirc.ui.CUSTOM_CLIENT = "custom"; | |
8 | ||
9 | qwebirc.ui.BaseUI = new Class({ | |
10 | Implements: [Events], | |
11 | initialize: function(parentElement, windowClass, uiName, options) { | |
12 | this.options = options; | |
13 | ||
14 | this.windows = {}; | |
15 | this.clients = {}; | |
16 | this.windows[qwebirc.ui.CUSTOM_CLIENT] = {}; | |
17 | this.windowArray = []; | |
18 | this.windowClass = windowClass; | |
19 | this.parentElement = parentElement; | |
20 | this.parentElement.addClass("qwebirc"); | |
21 | this.parentElement.addClass("qwebirc-" + uiName); | |
22 | this.firstClient = false; | |
23 | this.commandhistory = new qwebirc.irc.CommandHistory(); | |
24 | this.clientId = 0; | |
25 | }, | |
26 | newClient: function(client) { | |
27 | client.id = this.clientId++; | |
28 | client.hilightController = new qwebirc.ui.HilightController(client); | |
29 | ||
30 | this.windows[client.id] = {} | |
31 | this.clients[client.id] = client; | |
32 | var w = this.newWindow(client, qwebirc.ui.WINDOW_STATUS, "Status"); | |
33 | this.selectWindow(w); | |
34 | if(!this.firstClient) { | |
35 | this.firstClient = true; | |
36 | w.addLine("", "qwebirc v" + qwebirc.VERSION); | |
37 | w.addLine("", "Copyright (C) 2008-2009 Chris Porter. All rights reserved."); | |
38 | w.addLine("", "http://webchat.quakenet.org/"); | |
39 | w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org"); | |
40 | } | |
41 | return w; | |
42 | }, | |
43 | getClientId: function(client) { | |
44 | if(client == qwebirc.ui.CUSTOM_CLIENT) { | |
45 | return qwebirc.ui.CUSTOM_CLIENT; | |
46 | } else { | |
47 | return client.id; | |
48 | } | |
49 | }, | |
50 | getWindowIdentifier: function(type, name) { | |
51 | if(type == qwebirc.ui.WINDOW_MESSAGES) | |
52 | return "-M"; | |
53 | if(type == qwebirc.ui.WINDOW_STATUS) | |
54 | return ""; | |
55 | return "_" + name.toIRCLower(); | |
56 | }, | |
57 | newWindow: function(client, type, name) { | |
58 | var w = this.getWindow(client, type, name); | |
59 | if($defined(w)) | |
60 | return w; | |
61 | ||
62 | var wId = this.getWindowIdentifier(type, name); | |
63 | var w = this.windows[this.getClientId(client)][wId] = new this.windowClass(this, client, type, name, wId); | |
64 | this.windowArray.push(w); | |
65 | ||
66 | return w; | |
67 | }, | |
68 | getWindow: function(client, type, name) { | |
69 | var c = this.windows[this.getClientId(client)]; | |
70 | if(!$defined(c)) | |
71 | return null; | |
72 | ||
73 | return c[this.getWindowIdentifier(type, name)]; | |
74 | }, | |
75 | getActiveWindow: function() { | |
76 | return this.active; | |
77 | }, | |
78 | getActiveIRCWindow: function(client) { | |
79 | if(!this.active || this.active.type == qwebirc.ui.WINDOW_CUSTOM) { | |
80 | return this.windows[this.getClientId(client)][this.getWindowIdentifier(qwebirc.ui.WINDOW_STATUS)]; | |
81 | } else { | |
82 | return this.active; | |
83 | } | |
84 | }, | |
85 | __setActiveWindow: function(window) { | |
86 | this.active = window; | |
87 | }, | |
88 | selectWindow: function(window) { | |
89 | if(this.active) | |
90 | this.active.deselect(); | |
91 | window.select(); /* calls setActiveWindow */ | |
92 | document.title = window.name + " - " + this.options.appTitle; | |
93 | }, | |
94 | nextWindow: function(direction) { | |
95 | if(this.windowArray.length == 0 || !this.active) | |
96 | return; | |
97 | ||
98 | if(!direction) | |
99 | direction = 1; | |
100 | ||
101 | var index = this.windowArray.indexOf(this.active); | |
102 | if(index == -1) | |
103 | return; | |
104 | ||
105 | index = index + direction; | |
106 | if(index < 0) { | |
107 | index = this.windowArray.length - 1; | |
108 | } else if(index >= this.windowArray.length) { | |
109 | index = 0; | |
110 | } | |
111 | ||
112 | this.selectWindow(this.windowArray[index]); | |
113 | }, | |
114 | prevWindow: function() { | |
115 | this.nextWindow(-1); | |
116 | }, | |
117 | __closed: function(window) { | |
118 | if(window.active) { | |
119 | this.active = undefined; | |
120 | if(this.windowArray.length == 1) { | |
121 | this.windowArray = []; | |
122 | } else { | |
123 | var index = this.windowArray.indexOf(window); | |
124 | if(index == -1) { | |
125 | return; | |
126 | } else if(index == 0) { | |
127 | this.selectWindow(this.windowArray[1]); | |
128 | } else { | |
129 | this.selectWindow(this.windowArray[index - 1]); | |
130 | } | |
131 | } | |
132 | } | |
133 | ||
134 | this.windowArray = this.windowArray.erase(window); | |
135 | delete this.windows[this.getClientId(window.client)][window.identifier]; | |
136 | }, | |
137 | /* | |
138 | this shouldn't be called by overriding classes! | |
139 | they should implement their own! | |
140 | some form of user input MUST be received before an | |
141 | IRC connection is made, else users are going to get | |
142 | tricked into getting themselves glined | |
143 | */ | |
144 | loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) { | |
145 | qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick, this.options.networkName); | |
146 | } | |
147 | }); | |
148 | ||
149 | qwebirc.ui.StandardUI = new Class({ | |
150 | Extends: qwebirc.ui.BaseUI, | |
151 | UICommands: qwebirc.ui.UI_COMMANDS, | |
152 | initialize: function(parentElement, windowClass, uiName, options) { | |
153 | this.parent(parentElement, windowClass, uiName, options); | |
154 | ||
155 | this.tabCompleter = new qwebirc.ui.TabCompleterFactory(this); | |
156 | this.uiOptions = new qwebirc.ui.DefaultOptionsClass(this); | |
157 | this.customWindows = {}; | |
158 | ||
159 | if(Browser.Engine.trident) { | |
160 | ev = "keydown"; | |
161 | } else { | |
162 | ev = "keypress"; | |
163 | } | |
164 | document.addEvent(ev, this.__handleHotkey.bind(this)); | |
165 | }, | |
166 | __handleHotkey: function(x) { | |
167 | if(!x.alt || x.control) { | |
168 | if(x.key == "backspace" || x.key == "/") | |
169 | if(!this.getInputFocused(x)) | |
170 | new Event(x).stop(); | |
171 | return; | |
172 | } | |
173 | var success = false; | |
174 | if(x.key == "a" || x.key == "A") { | |
175 | var highestNum = 0; | |
176 | var highestIndex = -1; | |
177 | success = true; | |
178 | ||
179 | new Event(x).stop(); | |
180 | for(var i=0;i<this.windowArray.length;i++) { | |
181 | var h = this.windowArray[i].hilighted; | |
182 | if(h > highestNum) { | |
183 | highestIndex = i; | |
184 | highestNum = h; | |
185 | } | |
186 | } | |
187 | if(highestIndex > -1) | |
188 | this.selectWindow(this.windowArray[highestIndex]); | |
189 | } else if(x.key >= '0' && x.key <= '9') { | |
190 | success = true; | |
191 | ||
192 | number = x.key - '0'; | |
193 | if(number == 0) | |
194 | number = 10 | |
195 | ||
196 | number = number - 1; | |
197 | ||
198 | if(number >= this.windowArray.length) | |
199 | return; | |
200 | ||
201 | this.selectWindow(this.windowArray[number]); | |
202 | } else if(x.key == "left") { | |
203 | this.prevWindow(); | |
204 | success = true; | |
205 | } else if(x.key == "right") { | |
206 | this.nextWindow(); | |
207 | success = true; | |
208 | } | |
209 | if(success) | |
210 | new Event(x).stop(); | |
211 | }, | |
212 | getInputFocused: function(x) { | |
213 | if($$("input").indexOf(x.target) == -1 && $$("textarea").indexOf(x.target) == -1) | |
214 | return false; | |
215 | return true; | |
216 | }, | |
217 | newCustomWindow: function(name, select, type) { | |
218 | if(!type) | |
219 | type = qwebirc.ui.WINDOW_CUSTOM; | |
220 | ||
221 | var w = this.newWindow(qwebirc.ui.CUSTOM_CLIENT, type, name); | |
222 | w.addEvent("close", function(w) { | |
223 | delete this.windows[qwebirc.ui.CUSTOM_CLIENT][w.identifier]; | |
224 | }.bind(this)); | |
225 | ||
226 | if(select) | |
227 | this.selectWindow(w); | |
228 | ||
229 | return w; | |
230 | }, | |
231 | addCustomWindow: function(windowName, class_, cssClass, options) { | |
232 | if(!$defined(options)) | |
233 | options = {}; | |
234 | ||
235 | if(this.customWindows[windowName]) { | |
236 | this.selectWindow(this.customWindows[windowName]); | |
237 | return; | |
238 | } | |
239 | ||
240 | var d = this.newCustomWindow(windowName, true); | |
241 | this.customWindows[windowName] = d; | |
242 | ||
243 | d.addEvent("close", function() { | |
244 | this.customWindows[windowName] = null; | |
245 | }.bind(this)); | |
246 | ||
247 | if(cssClass) | |
248 | d.lines.addClass("qwebirc-" + cssClass); | |
249 | ||
250 | var ew = new class_(d.lines, options); | |
251 | ew.addEvent("close", function() { | |
252 | d.close(); | |
253 | }.bind(this)); | |
254 | ||
255 | d.setSubWindow(ew); | |
256 | }, | |
257 | embeddedWindow: function() { | |
258 | this.addCustomWindow("Embedding wizard", qwebirc.ui.EmbedWizard, "embeddedwizard"); | |
259 | }, | |
260 | optionsWindow: function() { | |
261 | this.addCustomWindow("Options", qwebirc.ui.OptionsPane, "optionspane", this.uiOptions); | |
262 | }, | |
263 | aboutWindow: function() { | |
264 | this.addCustomWindow("About", qwebirc.ui.AboutPane, "aboutpane", this.uiOptions); | |
265 | }, | |
266 | privacyWindow: function() { | |
267 | this.addCustomWindow("Privacy policy", qwebirc.ui.PrivacyPolicyPane, "privacypolicypane", this.uiOptions); | |
268 | }, | |
269 | feedbackWindow: function() { | |
270 | this.addCustomWindow("Feedback", qwebirc.ui.FeedbackPane, "feedbackpane", this.uiOptions); | |
271 | }, | |
272 | faqWindow: function() { | |
273 | this.addCustomWindow("FAQ", qwebirc.ui.FAQPane, "faqpane", this.uiOptions); | |
274 | }, | |
275 | urlDispatcher: function(name) { | |
276 | if(name == "embedded") | |
277 | return ["a", this.embeddedWindow.bind(this)]; | |
278 | ||
279 | if(name == "options") | |
280 | return ["a", this.optionsWindow.bind(this)]; | |
281 | ||
282 | return null; | |
283 | }, | |
284 | tabComplete: function(element) { | |
285 | this.tabCompleter.tabComplete(element); | |
286 | }, | |
287 | resetTabComplete: function() { | |
288 | this.tabCompleter.reset(); | |
289 | } | |
290 | }); | |
291 | ||
292 | qwebirc.ui.SoundUI = new Class({ | |
293 | Extends: qwebirc.ui.StandardUI, | |
294 | initialize: function(parentElement, windowClass, uiName, options) { | |
295 | this.parent(parentElement, windowClass, uiName, options); | |
296 | ||
297 | this.soundInited = false; | |
298 | this.soundReady = false; | |
299 | ||
300 | this.setBeepOnMention(this.uiOptions.BEEP_ON_MENTION); | |
301 | }, | |
302 | soundInit: function() { | |
303 | if(this.soundInited) | |
304 | return; | |
305 | if(!$defined(Browser.Plugins.Flash) || Browser.Plugins.Flash.version < 8) | |
306 | return; | |
307 | this.soundInited = true; | |
308 | ||
309 | this.soundPlayer = new qwebirc.sound.SoundPlayer(); | |
310 | this.soundPlayer.addEvent("ready", function() { | |
311 | this.soundReady = true; | |
312 | }.bind(this)); | |
313 | this.soundPlayer.go(); | |
314 | }, | |
315 | setBeepOnMention: function(value) { | |
316 | if(value) | |
317 | this.soundInit(); | |
318 | this.beepOnMention = value; | |
319 | }, | |
320 | beep: function() { | |
321 | if(!this.soundReady || !this.beepOnMention) | |
322 | return; | |
323 | ||
324 | this.soundPlayer.beep(); | |
325 | } | |
326 | }); | |
327 | ||
328 | qwebirc.ui.QuakeNetUI = new Class({ | |
329 | Extends: qwebirc.ui.SoundUI, | |
330 | urlDispatcher: function(name, window) { | |
331 | if(name == "qwhois") { | |
332 | return ["span", function(auth) { | |
333 | this.client.exec("/MSG Q whois #" + auth); | |
334 | }.bind(window)]; | |
335 | } | |
336 | if(name == "whois") { | |
337 | return ["span", function(nick) { | |
338 | this.client.exec("/WHOIS " + nick); | |
339 | }.bind(window)]; | |
340 | } | |
341 | return this.parent(name); | |
342 | }, | |
343 | logout: function() { | |
344 | if(!qwebirc.auth.loggedin()) | |
345 | return; | |
346 | if(confirm("Log out?")) { | |
347 | for(var client in this.clients) { | |
348 | this.clients[client].quit("Logged out"); | |
349 | }; | |
350 | document.location = "/auth?logout=1"; | |
351 | } | |
352 | } | |
353 | }); | |
354 | ||
355 | qwebirc.ui.NewLoginUI = new Class({ | |
356 | Extends: qwebirc.ui.QuakeNetUI, | |
357 | loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) { | |
358 | this.postInitialize(); | |
359 | ||
360 | var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT); | |
361 | var callback = function(args) { | |
362 | w.close(); | |
363 | callbackfn(args); | |
364 | }; | |
365 | ||
366 | qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick, this.options.networkName); | |
367 | } | |
368 | }); |