]>
Commit | Line | Data |
---|---|---|
1 | qwebirc.ui.supportsFocus = function() { | |
2 | var ua = navigator.userAgent; | |
3 | if(!$defined(ua)) | |
4 | return [true]; | |
5 | ||
6 | if(Browser.Engine.ipod || ua.indexOf("Konqueror") != -1) | |
7 | return [false, false]; | |
8 | ||
9 | return [true]; | |
10 | } | |
11 | ||
12 | /** | |
13 | * Note that options are settable by the uioptions url arg by default unless you specifiy | |
14 | * settableByURL... | |
15 | */ | |
16 | qwebirc.config.DEFAULT_OPTIONS = [ | |
17 | [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity (requires Flash)", true, { | |
18 | enabled: function() { | |
19 | if(!$defined(Browser.Plugins.Flash) || Browser.Plugins.Flash.version < 8) | |
20 | return [false, false]; /* [disabled, default_value] */ | |
21 | return [true]; | |
22 | }, | |
23 | get: function(value, ui) { | |
24 | if(ui.setBeepOnMention) | |
25 | ui.setBeepOnMention(value); | |
26 | } | |
27 | }], | |
28 | [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, { | |
29 | enabled: qwebirc.ui.supportsFocus | |
30 | }], | |
31 | [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false], | |
32 | [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false], | |
33 | [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in channel lines", true], | |
34 | [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true, { | |
35 | settableByURL: false | |
36 | }], | |
37 | [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true, { | |
38 | settableByURL: false | |
39 | }], | |
40 | [8, "LASTPOS_LINE", "Show a last position indicator for each window", true, { | |
41 | enabled: qwebirc.ui.supportsFocus | |
42 | }], | |
43 | [9, "NICK_COLOURS", "Automatically colour nicknames", false], | |
44 | [10, "HIDE_JOINPARTS", "Hide JOINS/PARTS/QUITS", false], | |
45 | [11, "STYLE_HUE", "Adjust user interface hue", function() { | |
46 | return {class_: qwebirc.config.HueOption, default_: 210}; | |
47 | }, { | |
48 | get: function(value, ui) { | |
49 | ui.setModifiableStylesheetValues(value, 0, 0); | |
50 | } | |
51 | }] | |
52 | ]; | |
53 | ||
54 | qwebirc.config.DefaultOptions = null; | |
55 | ||
56 | qwebirc.config.Input = new Class({ | |
57 | initialize: function(parent, option, position, parentObject) { | |
58 | this.option = option; | |
59 | this.value = option.value; | |
60 | this.enabled = this.option.enabled; | |
61 | this.position = position; | |
62 | this.parentElement = parent; | |
63 | this.parentObject = parentObject; | |
64 | ||
65 | this.render(); | |
66 | }, | |
67 | createInput: function(type, parent, name, selected) { | |
68 | if(!$defined(parent)) | |
69 | parent = this.parentElement; | |
70 | ||
71 | return qwebirc.util.createInput(type, parent, name, selected); | |
72 | }, | |
73 | FE: function(element, parent) { | |
74 | var n = new Element(element); | |
75 | if(!$defined(parent)) | |
76 | parent = this.parentElement; | |
77 | ||
78 | parent.appendChild(n); | |
79 | return n; | |
80 | }, | |
81 | focus: function() { | |
82 | this.mainElement.focus(); | |
83 | }, | |
84 | render: function() { | |
85 | this.event("render", this.mainElement); | |
86 | }, | |
87 | get: function(value) { | |
88 | this.event("get", [value, this.parentObject.optionObject.ui]); | |
89 | return value; | |
90 | }, | |
91 | event: function(name, x) { | |
92 | if(!$defined(this.option.extras)) | |
93 | return; | |
94 | var t = this.option.extras[name]; | |
95 | if(!$defined(t)) | |
96 | return; | |
97 | ||
98 | t.pass(x, this)(); | |
99 | }, | |
100 | cancel: function() { | |
101 | } | |
102 | }); | |
103 | ||
104 | qwebirc.config.TextInput = new Class({ | |
105 | Extends: qwebirc.config.Input, | |
106 | render: function() { | |
107 | var i = this.createInput("text"); | |
108 | this.mainElement = i; | |
109 | ||
110 | i.value = this.value; | |
111 | i.disabled = !this.enabled; | |
112 | ||
113 | this.parent(); | |
114 | }, | |
115 | get: function() { | |
116 | return this.parent(this.mainElement.value); | |
117 | } | |
118 | }); | |
119 | ||
120 | qwebirc.config.HueInput = new Class({ | |
121 | Extends: qwebirc.config.Input, | |
122 | render: function() { | |
123 | var i = new Element("div"); | |
124 | i.addClass("qwebirc-optionspane"); | |
125 | i.addClass("hue-slider"); | |
126 | this.parentElement.appendChild(i); | |
127 | ||
128 | var k = new Element("div"); | |
129 | k.addClass("knob"); | |
130 | if(Browser.Engine.trident) { | |
131 | k.setStyle("top", "0px"); | |
132 | k.setStyle("background-color", "black"); | |
133 | } | |
134 | ||
135 | i.appendChild(k); | |
136 | ||
137 | var slider = new Slider(i, k, {steps: 36, range: [0, 369], wheel: true}); | |
138 | slider.set(this.value); | |
139 | this.startValue = this.value; | |
140 | ||
141 | slider.addEvent("change", function(step) { | |
142 | this.value = step; | |
143 | this.get(); | |
144 | }.bind(this)); | |
145 | this.mainElement = i; | |
146 | ||
147 | if(!this.enabled) | |
148 | slider.detach(); | |
149 | ||
150 | this.parent(); | |
151 | }, | |
152 | get: function() { | |
153 | return this.parent(this.value); | |
154 | }, | |
155 | cancel: function() { | |
156 | this.value = this.startValue; | |
157 | this.get(); | |
158 | } | |
159 | }); | |
160 | ||
161 | qwebirc.config.CheckInput = new Class({ | |
162 | Extends: qwebirc.config.Input, | |
163 | render: function() { | |
164 | var i = this.createInput("checkbox"); | |
165 | this.mainElement = i; | |
166 | ||
167 | i.checked = this.value; | |
168 | i.disabled = !this.enabled; | |
169 | ||
170 | this.parent(); | |
171 | }, | |
172 | get: function() { | |
173 | return this.parent(this.mainElement.checked); | |
174 | } | |
175 | }); | |
176 | ||
177 | qwebirc.config.RadioInput = new Class({ | |
178 | Extends: qwebirc.config.Input, | |
179 | render: function() { | |
180 | var value = this.option.options; | |
181 | ||
182 | this.elements = []; | |
183 | ||
184 | for(var i=0;i<value.length;i++) { | |
185 | var d = this.FE("div", this.parentObject); | |
186 | var e = this.createInput("radio", d, "options_radio" + this.position, i == this.option.position); | |
187 | this.elements.push(e); | |
188 | e.disabled = !this.enabled; | |
189 | ||
190 | if(i == 0) | |
191 | this.mainElement = e; | |
192 | ||
193 | d.appendChild(document.createTextNode(value[i][0])); | |
194 | }; | |
195 | this.parent(); | |
196 | }, | |
197 | get: function() { | |
198 | for(var i=0;i<this.elements.length;i++) { | |
199 | var x = this.elements[i]; | |
200 | if(x.checked) { | |
201 | this.option.position = i; | |
202 | return this.parent(this.option.options[i][1]); | |
203 | } | |
204 | } | |
205 | } | |
206 | }); | |
207 | ||
208 | qwebirc.config.Option = new Class({ | |
209 | initialize: function(optionId, prefix, label, default_, extras) { | |
210 | this.prefix = prefix; | |
211 | this.label = label; | |
212 | this.default_ = default_; | |
213 | this.optionId = optionId; | |
214 | this.extras = extras; | |
215 | ||
216 | if($defined(extras) && $defined(extras.enabled)) { | |
217 | var enabledResult = extras.enabled(); | |
218 | this.enabled = enabledResult[0]; | |
219 | ||
220 | if(!enabledResult[0] && enabledResult.length > 1) | |
221 | this.default_ = enabledResult[1]; | |
222 | } else { | |
223 | this.enabled = true; | |
224 | } | |
225 | ||
226 | if($defined(extras) && $defined(extras.settableByURL)) { | |
227 | this.settableByURL = extras.settableByURL; | |
228 | } else { | |
229 | this.settableByURL = true; | |
230 | } | |
231 | }, | |
232 | setSavedValue: function(x) { | |
233 | if(this.enabled) | |
234 | this.value = x; | |
235 | } | |
236 | }); | |
237 | ||
238 | qwebirc.config.RadioOption = new Class({ | |
239 | Extends: qwebirc.config.Option, | |
240 | Element: qwebirc.config.RadioInput, | |
241 | initialize: function(optionId, prefix, label, default_, extras, options) { | |
242 | this.options = options.map(function(x) { | |
243 | if(typeof(x) == "string") | |
244 | return [x, x]; | |
245 | return x; | |
246 | }); | |
247 | this.defaultposition = default_; | |
248 | ||
249 | this.parent(optionId, prefix, label, this.options[default_][1], extras); | |
250 | }, | |
251 | setSavedValue: function(x) { | |
252 | for(var i=0;i<this.options.length;i++) { | |
253 | var y = this.options[i][1]; | |
254 | if(x == y) { | |
255 | this.position = i; | |
256 | this.value = x; | |
257 | return; | |
258 | } | |
259 | } | |
260 | this.position = this.defaultposition; | |
261 | this.value = this.default_; | |
262 | } | |
263 | }); | |
264 | ||
265 | qwebirc.config.TextOption = new Class({ | |
266 | Extends: qwebirc.config.Option, | |
267 | Element: qwebirc.config.TextInput | |
268 | }); | |
269 | ||
270 | qwebirc.config.CheckOption = new Class({ | |
271 | Extends: qwebirc.config.Option, | |
272 | Element: qwebirc.config.CheckInput | |
273 | }); | |
274 | ||
275 | qwebirc.config.HueOption = new Class({ | |
276 | Extends: qwebirc.config.Option, | |
277 | Element: qwebirc.config.HueInput | |
278 | }); | |
279 | ||
280 | qwebirc.ui.Options = new Class({ | |
281 | initialize: function(ui) { | |
282 | if(!$defined(qwebirc.config.DefaultOptions)) | |
283 | this.__configureDefaults(); | |
284 | ||
285 | this.optionList = qwebirc.config.DefaultOptions.slice(); | |
286 | this.optionHash = {} | |
287 | this.ui = ui; | |
288 | ||
289 | this._setup(); | |
290 | this.optionList.forEach(function(x) { | |
291 | x.setSavedValue(this._get(x)); | |
292 | this.optionHash[x.prefix] = x; | |
293 | this[x.prefix] = x.value; | |
294 | }.bind(this)); | |
295 | }, | |
296 | __configureDefaults: function() { | |
297 | qwebirc.config.DefaultOptions = qwebirc.config.DEFAULT_OPTIONS.map(function(x) { | |
298 | var optionId = x[0]; | |
299 | var prefix = x[1]; | |
300 | var label = x[2]; | |
301 | var default_ = x[3]; | |
302 | var moreextras = x[4]; | |
303 | var extras = x[5]; | |
304 | ||
305 | var stype = typeof(default_); | |
306 | if(stype == "number") { | |
307 | return new qwebirc.config.RadioOption(optionId, prefix, label, default_, moreextras, extra); | |
308 | } else { | |
309 | var type; | |
310 | if(stype == "boolean") { | |
311 | type = qwebirc.config.CheckOption; | |
312 | } else if(stype == "function") { | |
313 | var options = default_(); | |
314 | type = options.class_; | |
315 | default_ = options.default_; | |
316 | } else { | |
317 | type = qwebirc.config.TextOption; | |
318 | } | |
319 | return new type(optionId, prefix, label, default_, moreextras); | |
320 | } | |
321 | }); | |
322 | }, | |
323 | setValue: function(option, value) { | |
324 | this.optionHash[option.prefix].value = value; | |
325 | this[option.prefix] = value; | |
326 | }, | |
327 | getOptionList: function() { | |
328 | return this.optionList; | |
329 | }, | |
330 | _get: function(x) { | |
331 | return x.default_; | |
332 | }, | |
333 | _setup: function() { | |
334 | }, | |
335 | flush: function() { | |
336 | } | |
337 | }); | |
338 | ||
339 | qwebirc.ui.OptionsPane = new Class({ | |
340 | Implements: [Events], | |
341 | initialize: function(parentElement, optionObject) { | |
342 | this.parentElement = parentElement; | |
343 | this.optionObject = optionObject; | |
344 | ||
345 | this.createElements(); | |
346 | }, | |
347 | createElements: function() { | |
348 | var FE = function(element, parent) { | |
349 | var n = new Element(element); | |
350 | parent.appendChild(n); | |
351 | return n; | |
352 | }; | |
353 | ||
354 | var t = FE("table", this.parentElement); | |
355 | var tb = FE("tbody", t); | |
356 | ||
357 | this.boxList = []; | |
358 | ||
359 | var optList = this.optionObject.getOptionList(); | |
360 | for(var i=0;i<optList.length;i++) { | |
361 | var x = optList[i]; | |
362 | ||
363 | var row = FE("tr", tb); | |
364 | var cella = FE("td", row); | |
365 | cella.set("text", x.label + ":"); | |
366 | ||
367 | var cellb = FE("td", row); | |
368 | this.boxList.push([x, new x.Element(cellb, x, i, this)]); | |
369 | ||
370 | } | |
371 | ||
372 | var r = FE("tr", tb); | |
373 | var cella = FE("td", r); | |
374 | var cellb = FE("td", r); | |
375 | var save = qwebirc.util.createInput("submit", cellb); | |
376 | save.value = "Save"; | |
377 | ||
378 | save.addEvent("click", function() { | |
379 | this.save(); | |
380 | this.fireEvent("close"); | |
381 | }.bind(this)); | |
382 | ||
383 | var cancel = qwebirc.util.createInput("submit", cellb); | |
384 | cancel.value = "Cancel"; | |
385 | cancel.addEvent("click", function() { | |
386 | this.cancel(); | |
387 | this.fireEvent("close"); | |
388 | }.bind(this)); | |
389 | }, | |
390 | save: function() { | |
391 | this.boxList.forEach(function(x) { | |
392 | var option = x[0]; | |
393 | var box = x[1]; | |
394 | this.optionObject.setValue(option, box.get()); | |
395 | }.bind(this)); | |
396 | this.optionObject.flush(); | |
397 | }, | |
398 | cancel: function() { | |
399 | this.boxList.forEach(function(x) { | |
400 | x[1].cancel(); | |
401 | }.bind(this)); | |
402 | } | |
403 | }); | |
404 | ||
405 | qwebirc.ui.CookieOptions = new Class({ | |
406 | Extends: qwebirc.ui.Options, | |
407 | _setup: function() { | |
408 | this.__cookie = new Hash.Cookie("opt1", {duration: 3650, autoSave: false}); | |
409 | }, | |
410 | _get: function(x) { | |
411 | var v = this.__cookie.get(x.optionId); | |
412 | if(!$defined(v)) | |
413 | return x.default_; | |
414 | ||
415 | return v; | |
416 | }, | |
417 | flush: function() { | |
418 | this.__cookie.erase(); | |
419 | this._setup(); | |
420 | ||
421 | this.getOptionList().forEach(function(x) { | |
422 | this.__cookie.set(x.optionId, x.value); | |
423 | }.bind(this)); | |
424 | this.__cookie.save(); | |
425 | } | |
426 | }); | |
427 | ||
428 | qwebirc.ui.SuppliedArgOptions = new Class({ | |
429 | Extends: qwebirc.ui.CookieOptions, | |
430 | initialize: function(ui, arg) { | |
431 | var p = {}; | |
432 | ||
433 | if($defined(arg) && arg != "") { | |
434 | var decoded = qwebirc.util.b64Decode(arg); | |
435 | if(decoded) | |
436 | p = qwebirc.util.parseURI("?" + decoded); | |
437 | } | |
438 | ||
439 | this.parsedOptions = p; | |
440 | this.parent(ui); | |
441 | }, | |
442 | _get: function(x) { | |
443 | if(x.settableByURL !== true) | |
444 | return this.parent(x); | |
445 | ||
446 | var opt = this.parsedOptions[x.optionId]; | |
447 | if(!$defined(opt)) | |
448 | return this.parent(x); | |
449 | ||
450 | return opt; | |
451 | }, | |
452 | serialise: function() { | |
453 | var result = []; | |
454 | this.getOptionList().forEach(function(x) { | |
455 | if(x.settableByURL && x.default_ != x.value) | |
456 | result.push(x.optionId + "=" + x.value); | |
457 | }.bind(this)); | |
458 | ||
459 | return qwebirc.util.b64Encode(result.join("&")).replaceAll("=", ""); | |
460 | } | |
461 | }); | |
462 | ||
463 | qwebirc.ui.DefaultOptionsClass = new Class({ | |
464 | Extends: qwebirc.ui.SuppliedArgOptions | |
465 | }); |