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