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