]>
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({ |
2cad083e | 10 | Implements: [Events], |
a59dc700 | 11 | initialize: function(parentElement, windowClass, uiName, options) { |
2cad083e | 12 | this.options = options; |
a59dc700 | 13 | |
9e769c12 | 14 | this.windows = {}; |
ffbb638d | 15 | this.clients = {}; |
e20e5a6b | 16 | this.windows[qwebirc.ui.CUSTOM_CLIENT] = {}; |
9e769c12 CP |
17 | this.windowArray = []; |
18 | this.windowClass = windowClass; | |
19 | this.parentElement = parentElement; | |
20 | this.parentElement.addClass("qwebirc"); | |
21 | this.parentElement.addClass("qwebirc-" + uiName); | |
e8db8558 | 22 | this.firstClient = false; |
e20e5a6b | 23 | this.commandhistory = new qwebirc.irc.CommandHistory(); |
ffbb638d | 24 | this.clientId = 0; |
9e769c12 CP |
25 | }, |
26 | newClient: function(client) { | |
ffbb638d | 27 | client.id = this.clientId++; |
96f28062 CP |
28 | client.hilightController = new qwebirc.ui.HilightController(client); |
29 | ||
ffbb638d CP |
30 | this.windows[client.id] = {} |
31 | this.clients[client.id] = client; | |
e20e5a6b | 32 | var w = this.newWindow(client, qwebirc.ui.WINDOW_STATUS, "Status"); |
9e769c12 | 33 | this.selectWindow(w); |
e8db8558 CP |
34 | if(!this.firstClient) { |
35 | this.firstClient = true; | |
e20e5a6b | 36 | w.addLine("", "qwebirc v" + qwebirc.VERSION); |
2dfab0e1 CP |
37 | w.addLine("", "Copyright (C) 2008-2009 Chris Porter and the qwebirc project."); |
38 | w.addLine("", "http://www.qwebirc.org"); | |
39 | w.addLine("", "Licensed under the GNU General Public License, Version 2."); | |
e8db8558 | 40 | } |
9e769c12 CP |
41 | return w; |
42 | }, | |
ffbb638d CP |
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 | }, | |
fd3734d4 | 50 | getWindowIdentifier: function(client, type, name) { |
f74802c5 CP |
51 | if(type == qwebirc.ui.WINDOW_MESSAGES) |
52 | return "-M"; | |
e20e5a6b | 53 | if(type == qwebirc.ui.WINDOW_STATUS) |
f74802c5 | 54 | return ""; |
fd3734d4 CP |
55 | |
56 | if(client == qwebirc.ui.CUSTOM_CLIENT) /* HACK */ | |
57 | return "_" + name; | |
58 | ||
59 | return "_" + client.toIRCLower(name); | |
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 | |
fd3734d4 | 66 | var wId = this.getWindowIdentifier(client, type, name); |
f74802c5 | 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 | ||
fd3734d4 | 77 | return c[this.getWindowIdentifier(client, type, name)]; |
f74802c5 | 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) { | |
fd3734d4 | 84 | return this.windows[this.getClientId(client)][this.getWindowIdentifier(client, 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 */ | |
326478c2 CP |
96 | this.updateTitle(window.name + " - " + this.options.appTitle); |
97 | }, | |
98 | updateTitle: function(text) { | |
99 | document.title = text; | |
9e769c12 | 100 | }, |
ff4befd8 CP |
101 | nextWindow: function(direction) { |
102 | if(this.windowArray.length == 0 || !this.active) | |
103 | return; | |
104 | ||
105 | if(!direction) | |
106 | direction = 1; | |
107 | ||
108 | var index = this.windowArray.indexOf(this.active); | |
109 | if(index == -1) | |
110 | return; | |
111 | ||
112 | index = index + direction; | |
113 | if(index < 0) { | |
114 | index = this.windowArray.length - 1; | |
115 | } else if(index >= this.windowArray.length) { | |
116 | index = 0; | |
117 | } | |
118 | ||
119 | this.selectWindow(this.windowArray[index]); | |
120 | }, | |
121 | prevWindow: function() { | |
122 | this.nextWindow(-1); | |
123 | }, | |
9e769c12 CP |
124 | __closed: function(window) { |
125 | if(window.active) { | |
126 | this.active = undefined; | |
127 | if(this.windowArray.length == 1) { | |
128 | this.windowArray = []; | |
129 | } else { | |
130 | var index = this.windowArray.indexOf(window); | |
6f2e4a37 CP |
131 | if(index == -1) { |
132 | return; | |
133 | } else if(index == 0) { | |
9e769c12 CP |
134 | this.selectWindow(this.windowArray[1]); |
135 | } else { | |
136 | this.selectWindow(this.windowArray[index - 1]); | |
137 | } | |
9e769c12 CP |
138 | } |
139 | } | |
140 | ||
404cfb58 | 141 | this.windowArray = this.windowArray.erase(window); |
ffbb638d | 142 | delete this.windows[this.getClientId(window.client)][window.identifier]; |
eb9b087b | 143 | }, |
eb9b087b CP |
144 | /* |
145 | this shouldn't be called by overriding classes! | |
66de775f | 146 | they should implement their own! |
eb9b087b CP |
147 | some form of user input MUST be received before an |
148 | IRC connection is made, else users are going to get | |
149 | tricked into getting themselves glined | |
150 | */ | |
66de775f | 151 | loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) { |
2cad083e | 152 | qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick, this.options.networkName); |
9e769c12 CP |
153 | } |
154 | }); | |
381fddfd | 155 | |
e20e5a6b CP |
156 | qwebirc.ui.StandardUI = new Class({ |
157 | Extends: qwebirc.ui.BaseUI, | |
f3d0c9f5 | 158 | UICommands: qwebirc.ui.UI_COMMANDS, |
381fddfd CP |
159 | initialize: function(parentElement, windowClass, uiName, options) { |
160 | this.parent(parentElement, windowClass, uiName, options); | |
3184781b CP |
161 | |
162 | this.tabCompleter = new qwebirc.ui.TabCompleterFactory(this); | |
fb71087a | 163 | this.uiOptions = new qwebirc.ui.DefaultOptionsClass(this); |
ebb21d2e CP |
164 | this.customWindows = {}; |
165 | ||
2a802692 | 166 | var ev; |
20157c51 CP |
167 | if(Browser.Engine.trident) { |
168 | ev = "keydown"; | |
169 | } else { | |
170 | ev = "keypress"; | |
171 | } | |
172 | document.addEvent(ev, this.__handleHotkey.bind(this)); | |
173 | }, | |
174 | __handleHotkey: function(x) { | |
175 | if(!x.alt || x.control) { | |
176 | if(x.key == "backspace" || x.key == "/") | |
177 | if(!this.getInputFocused(x)) | |
178 | new Event(x).stop(); | |
179 | return; | |
180 | } | |
181 | var success = false; | |
182 | if(x.key == "a" || x.key == "A") { | |
183 | var highestNum = 0; | |
184 | var highestIndex = -1; | |
185 | success = true; | |
186 | ||
187 | new Event(x).stop(); | |
188 | for(var i=0;i<this.windowArray.length;i++) { | |
189 | var h = this.windowArray[i].hilighted; | |
190 | if(h > highestNum) { | |
191 | highestIndex = i; | |
192 | highestNum = h; | |
381fddfd | 193 | } |
20157c51 CP |
194 | } |
195 | if(highestIndex > -1) | |
196 | this.selectWindow(this.windowArray[highestIndex]); | |
197 | } else if(x.key >= '0' && x.key <= '9') { | |
198 | success = true; | |
199 | ||
200 | number = x.key - '0'; | |
201 | if(number == 0) | |
202 | number = 10 | |
424608ac | 203 | |
20157c51 CP |
204 | number = number - 1; |
205 | ||
206 | if(number >= this.windowArray.length) | |
207 | return; | |
381fddfd | 208 | |
20157c51 CP |
209 | this.selectWindow(this.windowArray[number]); |
210 | } else if(x.key == "left") { | |
211 | this.prevWindow(); | |
212 | success = true; | |
213 | } else if(x.key == "right") { | |
214 | this.nextWindow(); | |
215 | success = true; | |
216 | } | |
217 | if(success) | |
218 | new Event(x).stop(); | |
219 | }, | |
220 | getInputFocused: function(x) { | |
deebe19a CP |
221 | if($$("input").indexOf(x.target) == -1 && $$("textarea").indexOf(x.target) == -1) |
222 | return false; | |
223 | return true; | |
841a451d | 224 | }, |
8af49135 CP |
225 | newCustomWindow: function(name, select, type) { |
226 | if(!type) | |
e20e5a6b | 227 | type = qwebirc.ui.WINDOW_CUSTOM; |
8af49135 | 228 | |
e20e5a6b | 229 | var w = this.newWindow(qwebirc.ui.CUSTOM_CLIENT, type, name); |
8af49135 | 230 | w.addEvent("close", function(w) { |
f74802c5 | 231 | delete this.windows[qwebirc.ui.CUSTOM_CLIENT][w.identifier]; |
8af49135 CP |
232 | }.bind(this)); |
233 | ||
234 | if(select) | |
235 | this.selectWindow(w); | |
6c19eb8f | 236 | |
8af49135 CP |
237 | return w; |
238 | }, | |
ebb21d2e CP |
239 | addCustomWindow: function(windowName, class_, cssClass, options) { |
240 | if(!$defined(options)) | |
241 | options = {}; | |
242 | ||
243 | if(this.customWindows[windowName]) { | |
244 | this.selectWindow(this.customWindows[windowName]); | |
8af49135 | 245 | return; |
841a451d | 246 | } |
8af49135 | 247 | |
ebb21d2e CP |
248 | var d = this.newCustomWindow(windowName, true); |
249 | this.customWindows[windowName] = d; | |
250 | ||
251 | d.addEvent("close", function() { | |
252 | this.customWindows[windowName] = null; | |
8af49135 CP |
253 | }.bind(this)); |
254 | ||
ebb21d2e | 255 | if(cssClass) |
e1a91a8a | 256 | d.lines.addClass("qwebirc-" + cssClass); |
ebb21d2e CP |
257 | |
258 | var ew = new class_(d.lines, options); | |
8af49135 | 259 | ew.addEvent("close", function() { |
ebb21d2e | 260 | d.close(); |
8af49135 | 261 | }.bind(this)); |
17f40fd9 CP |
262 | |
263 | d.setSubWindow(ew); | |
841a451d | 264 | }, |
ebb21d2e | 265 | embeddedWindow: function() { |
2dfab0e1 | 266 | this.addCustomWindow("Embedding wizard", qwebirc.ui.EmbedWizard, "embeddedwizard", {baseURL: this.options.baseURL}); |
ebb21d2e CP |
267 | }, |
268 | optionsWindow: function() { | |
269 | this.addCustomWindow("Options", qwebirc.ui.OptionsPane, "optionspane", this.uiOptions); | |
270 | }, | |
e1a91a8a CP |
271 | aboutWindow: function() { |
272 | this.addCustomWindow("About", qwebirc.ui.AboutPane, "aboutpane", this.uiOptions); | |
273 | }, | |
b35116e2 CP |
274 | privacyWindow: function() { |
275 | this.addCustomWindow("Privacy policy", qwebirc.ui.PrivacyPolicyPane, "privacypolicypane", this.uiOptions); | |
276 | }, | |
391f51ff CP |
277 | feedbackWindow: function() { |
278 | this.addCustomWindow("Feedback", qwebirc.ui.FeedbackPane, "feedbackpane", this.uiOptions); | |
279 | }, | |
f3d0c9f5 CP |
280 | faqWindow: function() { |
281 | this.addCustomWindow("FAQ", qwebirc.ui.FAQPane, "faqpane", this.uiOptions); | |
282 | }, | |
144ee52f | 283 | urlDispatcher: function(name, window) { |
8af49135 | 284 | if(name == "embedded") |
925fc357 | 285 | return ["a", this.embeddedWindow.bind(this)]; |
ebb21d2e CP |
286 | |
287 | if(name == "options") | |
288 | return ["a", this.optionsWindow.bind(this)]; | |
8af49135 | 289 | |
5f2808af CP |
290 | /* doesn't really belong here */ |
291 | if(name == "whois") { | |
292 | return ["span", function(nick) { | |
293 | this.client.exec("/WHOIS " + nick); | |
294 | }.bind(window)]; | |
295 | } | |
296 | ||
8af49135 | 297 | return null; |
3184781b CP |
298 | }, |
299 | tabComplete: function(element) { | |
300 | this.tabCompleter.tabComplete(element); | |
301 | }, | |
302 | resetTabComplete: function() { | |
303 | this.tabCompleter.reset(); | |
8af49135 | 304 | } |
381fddfd | 305 | }); |
6f2e4a37 | 306 | |
326478c2 | 307 | qwebirc.ui.NotificationUI = new Class({ |
e20e5a6b | 308 | Extends: qwebirc.ui.StandardUI, |
fb71087a CP |
309 | initialize: function(parentElement, windowClass, uiName, options) { |
310 | this.parent(parentElement, windowClass, uiName, options); | |
311 | ||
326478c2 CP |
312 | this.__beeper = new qwebirc.ui.Beeper(this.uiOptions); |
313 | this.__flasher = new qwebirc.ui.Flasher(this.uiOptions); | |
fb71087a | 314 | |
326478c2 | 315 | this.beep = this.__beeper.beep.bind(this.__beeper); |
127631e0 | 316 | |
326478c2 CP |
317 | this.flash = this.__flasher.flash.bind(this.__flasher); |
318 | this.cancelFlash = this.__flasher.cancelFlash.bind(this.__flasher); | |
fb71087a | 319 | }, |
127631e0 CP |
320 | setBeepOnMention: function(value) { |
321 | if(value) | |
326478c2 CP |
322 | this.__beeper.soundInit(); |
323 | }, | |
324 | updateTitle: function(text) { | |
325 | if(this.__flasher.updateTitle(text)) | |
326 | this.parent(text); | |
1211ddcd | 327 | } |
fb71087a CP |
328 | }); |
329 | ||
5f2808af | 330 | qwebirc.ui.NewLoginUI = new Class({ |
326478c2 | 331 | Extends: qwebirc.ui.NotificationUI, |
5f2808af CP |
332 | loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) { |
333 | this.postInitialize(); | |
334 | ||
335 | var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT); | |
336 | var callback = function(args) { | |
337 | w.close(); | |
338 | callbackfn(args); | |
339 | }; | |
340 | ||
341 | qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick, this.options.networkName); | |
342 | } | |
343 | }); | |
344 | ||
345 | qwebirc.ui.QuakeNetUI = new Class({ | |
346 | Extends: qwebirc.ui.NewLoginUI, | |
2cd9e32d CP |
347 | urlDispatcher: function(name, window) { |
348 | if(name == "qwhois") { | |
7cb09779 | 349 | return ["span", function(auth) { |
2cd9e32d | 350 | this.client.exec("/MSG Q whois #" + auth); |
925fc357 CP |
351 | }.bind(window)]; |
352 | } | |
144ee52f | 353 | return this.parent(name, window); |
ffbb638d CP |
354 | }, |
355 | logout: function() { | |
356 | if(!qwebirc.auth.loggedin()) | |
357 | return; | |
358 | if(confirm("Log out?")) { | |
359 | for(var client in this.clients) { | |
360 | this.clients[client].quit("Logged out"); | |
361 | }; | |
4b9f894d CP |
362 | |
363 | /* HACK */ | |
364 | var foo = function() { document.location = "/auth?logout=1"; }; | |
365 | foo.delay(500); | |
ffbb638d | 366 | } |
2cd9e32d CP |
367 | } |
368 | }); | |
144ee52f CP |
369 | |
370 | qwebirc.ui.RootUI = qwebirc.ui.QuakeNetUI; |