]>
Commit | Line | Data |
---|---|---|
85449eee CP |
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 | ||
c0f2f367 CP |
12 | /** |
13 | * Note that options are settable by the uioptions url arg by default unless you specifiy | |
14 | * settableByURL... | |
15 | */ | |
ebb21d2e | 16 | qwebirc.config.DEFAULT_OPTIONS = [ |
f63006ab | 17 | [1, "BEEP_ON_MENTION", "Beep on activity", true, { |
82cf3f26 | 18 | applyChanges: function(value, ui) { |
127631e0 CP |
19 | if(ui.setBeepOnMention) |
20 | ui.setBeepOnMention(value); | |
fb71087a CP |
21 | } |
22 | }], | |
f63006ab CP |
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 | }], | |
2fb3b3b0 | 34 | [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, { |
85449eee | 35 | enabled: qwebirc.ui.supportsFocus |
2fb3b3b0 | 36 | }], |
7af2d0c1 CP |
37 | [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false], |
38 | [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false], | |
9aea28e8 | 39 | [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in channel lines", true], |
65f2c94c | 40 | [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", false, { |
c0f2f367 CP |
41 | settableByURL: false |
42 | }], | |
43 | [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true, { | |
44 | settableByURL: false | |
45 | }], | |
85449eee CP |
46 | [8, "LASTPOS_LINE", "Show a last position indicator for each window", true, { |
47 | enabled: qwebirc.ui.supportsFocus | |
48 | }], | |
0a5b0904 | 49 | [9, "NICK_COLOURS", "Automatically colour nicknames", false], |
889ecb33 | 50 | [10, "HIDE_JOINPARTS", "Hide JOINS/PARTS/QUITS", false], |
ffb5ea9a CP |
51 | [11, "STYLE_HUE", "Adjust user interface hue", function(ui) { |
52 | return {class_: qwebirc.config.HueOption, default_: ui.__styleValues.hue}; | |
889ecb33 | 53 | }, { |
82cf3f26 | 54 | applyChanges: function(value, ui) { |
6f8a20df | 55 | ui.setModifiableStylesheetValues({hue: value}); |
889ecb33 | 56 | } |
cbef082a | 57 | }], |
5f464ed5 | 58 | [12, "QUERY_ON_NICK_CLICK", "Query on nickname click in channel", false], |
22538fb7 | 59 | [13, "SHOW_NICKLIST", "Show nickname list in channels", qwebirc.util.deviceHasKeyboard()], |
a4a71818 CP |
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 | }] | |
ebb21d2e CP |
71 | ]; |
72 | ||
73 | qwebirc.config.DefaultOptions = null; | |
74 | ||
c38a0240 | 75 | qwebirc.config.Input = new Class({ |
fb71087a | 76 | initialize: function(parent, option, position, parentObject) { |
c38a0240 CP |
77 | this.option = option; |
78 | this.value = option.value; | |
2fb3b3b0 | 79 | this.enabled = this.option.enabled; |
c38a0240 | 80 | this.position = position; |
fb71087a CP |
81 | this.parentElement = parent; |
82 | this.parentObject = parentObject; | |
c38a0240 CP |
83 | |
84 | this.render(); | |
85 | }, | |
a9cbd00d | 86 | createInput: function(type, parent, name, selected, id) { |
a1e826c7 CP |
87 | if(!$defined(parent)) |
88 | parent = this.parentElement; | |
89 | ||
a9cbd00d | 90 | return qwebirc.util.createInput(type, parent, name, selected, this.option.id); |
a1e826c7 | 91 | }, |
c38a0240 CP |
92 | FE: function(element, parent) { |
93 | var n = new Element(element); | |
94 | if(!$defined(parent)) | |
fb71087a | 95 | parent = this.parentElement; |
c38a0240 CP |
96 | |
97 | parent.appendChild(n); | |
98 | return n; | |
99 | }, | |
100 | focus: function() { | |
101 | this.mainElement.focus(); | |
fb71087a CP |
102 | }, |
103 | render: function() { | |
104 | this.event("render", this.mainElement); | |
105 | }, | |
82cf3f26 CP |
106 | applyChanges: function() { |
107 | this.event("applyChanges", [this.get(), this.parentObject.optionObject.ui]); | |
fb71087a CP |
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)(); | |
889ecb33 CP |
117 | }, |
118 | cancel: function() { | |
c38a0240 CP |
119 | } |
120 | }); | |
121 | ||
122 | qwebirc.config.TextInput = new Class({ | |
123 | Extends: qwebirc.config.Input, | |
124 | render: function() { | |
a1e826c7 | 125 | var i = this.createInput("text"); |
c38a0240 CP |
126 | this.mainElement = i; |
127 | ||
c38a0240 | 128 | i.value = this.value; |
2fb3b3b0 CP |
129 | i.disabled = !this.enabled; |
130 | ||
fb71087a | 131 | this.parent(); |
c38a0240 CP |
132 | }, |
133 | get: function() { | |
82cf3f26 | 134 | return this.mainElement.value; |
c38a0240 CP |
135 | } |
136 | }); | |
137 | ||
889ecb33 CP |
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"); | |
889ecb33 CP |
144 | this.parentElement.appendChild(i); |
145 | ||
146 | var k = new Element("div"); | |
147 | k.addClass("knob"); | |
1f7d5f9e CP |
148 | if(Browser.Engine.trident) { |
149 | k.setStyle("top", "0px"); | |
150 | k.setStyle("background-color", "black"); | |
151 | } | |
152 | ||
889ecb33 CP |
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; | |
82cf3f26 | 161 | this.applyChanges(); |
889ecb33 CP |
162 | }.bind(this)); |
163 | this.mainElement = i; | |
164 | ||
165 | if(!this.enabled) | |
166 | slider.detach(); | |
167 | ||
168 | this.parent(); | |
169 | }, | |
170 | get: function() { | |
82cf3f26 | 171 | return this.value; |
889ecb33 CP |
172 | }, |
173 | cancel: function() { | |
174 | this.value = this.startValue; | |
82cf3f26 | 175 | this.applyChanges(); |
889ecb33 CP |
176 | } |
177 | }); | |
178 | ||
c38a0240 CP |
179 | qwebirc.config.CheckInput = new Class({ |
180 | Extends: qwebirc.config.Input, | |
181 | render: function() { | |
a9cbd00d | 182 | var i = this.createInput("checkbox", null, null, null, this.id); |
c38a0240 CP |
183 | this.mainElement = i; |
184 | ||
c38a0240 | 185 | i.checked = this.value; |
2fb3b3b0 CP |
186 | i.disabled = !this.enabled; |
187 | ||
fb71087a | 188 | this.parent(); |
c38a0240 CP |
189 | }, |
190 | get: function() { | |
82cf3f26 | 191 | return this.mainElement.checked; |
c38a0240 CP |
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 = []; | |
2fb3b3b0 | 201 | |
c38a0240 CP |
202 | for(var i=0;i<value.length;i++) { |
203 | var d = this.FE("div", this.parentObject); | |
a1e826c7 | 204 | var e = this.createInput("radio", d, "options_radio" + this.position, i == this.option.position); |
c38a0240 | 205 | this.elements.push(e); |
2fb3b3b0 CP |
206 | e.disabled = !this.enabled; |
207 | ||
c38a0240 CP |
208 | if(i == 0) |
209 | this.mainElement = e; | |
210 | ||
211 | d.appendChild(document.createTextNode(value[i][0])); | |
212 | }; | |
fb71087a | 213 | this.parent(); |
c38a0240 CP |
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; | |
82cf3f26 | 220 | return this.option.options[i][1]; |
c38a0240 CP |
221 | } |
222 | } | |
223 | } | |
224 | }); | |
225 | ||
ebb21d2e | 226 | qwebirc.config.Option = new Class({ |
fb71087a | 227 | initialize: function(optionId, prefix, label, default_, extras) { |
c38a0240 | 228 | this.prefix = prefix; |
ebb21d2e | 229 | this.label = label; |
c38a0240 CP |
230 | this.default_ = default_; |
231 | this.optionId = optionId; | |
fb71087a | 232 | this.extras = extras; |
2fb3b3b0 CP |
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; | |
c0f2f367 CP |
242 | } |
243 | ||
244 | if($defined(extras) && $defined(extras.settableByURL)) { | |
245 | this.settableByURL = extras.settableByURL; | |
246 | } else { | |
247 | this.settableByURL = true; | |
248 | } | |
c38a0240 CP |
249 | }, |
250 | setSavedValue: function(x) { | |
01343497 CP |
251 | if(this.enabled) |
252 | this.value = x; | |
1f7d5f9e | 253 | } |
ebb21d2e CP |
254 | }); |
255 | ||
c38a0240 CP |
256 | qwebirc.config.RadioOption = new Class({ |
257 | Extends: qwebirc.config.Option, | |
258 | Element: qwebirc.config.RadioInput, | |
fb71087a | 259 | initialize: function(optionId, prefix, label, default_, extras, options) { |
c38a0240 CP |
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 | ||
fb71087a | 267 | this.parent(optionId, prefix, label, this.options[default_][1], extras); |
c38a0240 CP |
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 | ||
889ecb33 CP |
293 | qwebirc.config.HueOption = new Class({ |
294 | Extends: qwebirc.config.Option, | |
295 | Element: qwebirc.config.HueInput | |
296 | }); | |
297 | ||
ebb21d2e | 298 | qwebirc.ui.Options = new Class({ |
fb71087a | 299 | initialize: function(ui) { |
ffb5ea9a CP |
300 | this.ui = ui; |
301 | ||
ebb21d2e CP |
302 | if(!$defined(qwebirc.config.DefaultOptions)) |
303 | this.__configureDefaults(); | |
304 | ||
c38a0240 | 305 | this.optionList = qwebirc.config.DefaultOptions.slice(); |
ffb5ea9a CP |
306 | this.optionHash = {}; |
307 | ||
c38a0240 CP |
308 | this._setup(); |
309 | this.optionList.forEach(function(x) { | |
310 | x.setSavedValue(this._get(x)); | |
311 | this.optionHash[x.prefix] = x; | |
312 | this[x.prefix] = x.value; | |
ebb21d2e CP |
313 | }.bind(this)); |
314 | }, | |
315 | __configureDefaults: function() { | |
c38a0240 CP |
316 | qwebirc.config.DefaultOptions = qwebirc.config.DEFAULT_OPTIONS.map(function(x) { |
317 | var optionId = x[0]; | |
318 | var prefix = x[1]; | |
319 | var label = x[2]; | |
320 | var default_ = x[3]; | |
fb71087a CP |
321 | var moreextras = x[4]; |
322 | var extras = x[5]; | |
ebb21d2e | 323 | |
c38a0240 CP |
324 | var stype = typeof(default_); |
325 | if(stype == "number") { | |
fb71087a | 326 | return new qwebirc.config.RadioOption(optionId, prefix, label, default_, moreextras, extra); |
ebb21d2e | 327 | } else { |
c38a0240 CP |
328 | var type; |
329 | if(stype == "boolean") { | |
330 | type = qwebirc.config.CheckOption; | |
b076b3ab | 331 | } else if(stype == "function") { |
ffb5ea9a | 332 | var options = default_.call(this, this.ui); |
889ecb33 | 333 | type = options.class_; |
b076b3ab CP |
334 | default_ = options.default_; |
335 | } else { | |
336 | type = qwebirc.config.TextOption; | |
c38a0240 | 337 | } |
fb71087a | 338 | return new type(optionId, prefix, label, default_, moreextras); |
ebb21d2e | 339 | } |
ffb5ea9a | 340 | }, this); |
c38a0240 CP |
341 | }, |
342 | setValue: function(option, value) { | |
343 | this.optionHash[option.prefix].value = value; | |
344 | this[option.prefix] = value; | |
345 | }, | |
ffb5ea9a CP |
346 | setValueByPrefix: function(prefix, value) { |
347 | this.optionHash[prefix].value = value; | |
348 | this[prefix] = value; | |
349 | }, | |
c38a0240 CP |
350 | getOptionList: function() { |
351 | return this.optionList; | |
352 | }, | |
353 | _get: function(x) { | |
354 | return x.default_; | |
355 | }, | |
356 | _setup: function() { | |
357 | }, | |
358 | flush: function() { | |
ebb21d2e CP |
359 | } |
360 | }); | |
361 | ||
362 | qwebirc.ui.OptionsPane = new Class({ | |
c38a0240 CP |
363 | Implements: [Events], |
364 | initialize: function(parentElement, optionObject) { | |
ebb21d2e | 365 | this.parentElement = parentElement; |
c38a0240 | 366 | this.optionObject = optionObject; |
ebb21d2e CP |
367 | |
368 | this.createElements(); | |
369 | }, | |
370 | createElements: function() { | |
371 | var FE = function(element, parent) { | |
372 | var n = new Element(element); | |
373 | parent.appendChild(n); | |
374 | return n; | |
375 | }; | |
ebb21d2e CP |
376 | |
377 | var t = FE("table", this.parentElement); | |
378 | var tb = FE("tbody", t); | |
379 | ||
c38a0240 CP |
380 | this.boxList = []; |
381 | ||
382 | var optList = this.optionObject.getOptionList(); | |
383 | for(var i=0;i<optList.length;i++) { | |
384 | var x = optList[i]; | |
385 | ||
ebb21d2e CP |
386 | var row = FE("tr", tb); |
387 | var cella = FE("td", row); | |
a9cbd00d CP |
388 | |
389 | x.id = qwebirc.util.generateID(); | |
390 | var label = new Element("label", {"for": x.id}); | |
391 | cella.appendChild(label); | |
392 | label.set("text", x.label + ":"); | |
c38a0240 | 393 | |
ebb21d2e | 394 | var cellb = FE("td", row); |
fb71087a | 395 | this.boxList.push([x, new x.Element(cellb, x, i, this)]); |
c38a0240 | 396 | |
c38a0240 CP |
397 | } |
398 | ||
399 | var r = FE("tr", tb); | |
400 | var cella = FE("td", r); | |
401 | var cellb = FE("td", r); | |
a1e826c7 | 402 | var save = qwebirc.util.createInput("submit", cellb); |
c38a0240 CP |
403 | save.value = "Save"; |
404 | ||
405 | save.addEvent("click", function() { | |
406 | this.save(); | |
407 | this.fireEvent("close"); | |
408 | }.bind(this)); | |
409 | ||
a1e826c7 | 410 | var cancel = qwebirc.util.createInput("submit", cellb); |
c38a0240 CP |
411 | cancel.value = "Cancel"; |
412 | cancel.addEvent("click", function() { | |
889ecb33 | 413 | this.cancel(); |
c38a0240 CP |
414 | this.fireEvent("close"); |
415 | }.bind(this)); | |
416 | }, | |
417 | save: function() { | |
418 | this.boxList.forEach(function(x) { | |
419 | var option = x[0]; | |
420 | var box = x[1]; | |
421 | this.optionObject.setValue(option, box.get()); | |
ebb21d2e | 422 | }.bind(this)); |
82cf3f26 CP |
423 | this.boxList.forEach(function(x) { |
424 | x[1].applyChanges(); | |
ebb21d2e | 425 | }.bind(this)); |
c38a0240 | 426 | this.optionObject.flush(); |
889ecb33 CP |
427 | }, |
428 | cancel: function() { | |
429 | this.boxList.forEach(function(x) { | |
430 | x[1].cancel(); | |
431 | }.bind(this)); | |
ebb21d2e CP |
432 | } |
433 | }); | |
c38a0240 CP |
434 | |
435 | qwebirc.ui.CookieOptions = new Class({ | |
436 | Extends: qwebirc.ui.Options, | |
437 | _setup: function() { | |
438 | this.__cookie = new Hash.Cookie("opt1", {duration: 3650, autoSave: false}); | |
439 | }, | |
440 | _get: function(x) { | |
441 | var v = this.__cookie.get(x.optionId); | |
442 | if(!$defined(v)) | |
443 | return x.default_; | |
444 | ||
445 | return v; | |
446 | }, | |
447 | flush: function() { | |
448 | this.__cookie.erase(); | |
449 | this._setup(); | |
450 | ||
451 | this.getOptionList().forEach(function(x) { | |
452 | this.__cookie.set(x.optionId, x.value); | |
453 | }.bind(this)); | |
454 | this.__cookie.save(); | |
455 | } | |
456 | }); | |
457 | ||
c0f2f367 CP |
458 | qwebirc.ui.SuppliedArgOptions = new Class({ |
459 | Extends: qwebirc.ui.CookieOptions, | |
460 | initialize: function(ui, arg) { | |
ea29e3d7 | 461 | var p = new QHash(); |
c0f2f367 | 462 | |
8d1217eb CP |
463 | if($defined(arg) && arg != "" && arg.length > 2) { |
464 | var checksum = arg.substr(arg.length - 2, 2); | |
465 | var decoded = qwebirc.util.b64Decode(arg.substr(0, arg.length - 2)); | |
466 | ||
10d70bfb CP |
467 | if(decoded && (new qwebirc.util.crypto.MD5().digest(decoded).slice(0, 2) == checksum)) { |
468 | var p2 = qwebirc.util.parseURI("?" + decoded); | |
ea29e3d7 CP |
469 | p2.each(function(k, v) { |
470 | p.put(k, JSON.decode(v, true)); | |
471 | }); | |
10d70bfb | 472 | } |
c0f2f367 CP |
473 | } |
474 | ||
475 | this.parsedOptions = p; | |
476 | this.parent(ui); | |
477 | }, | |
478 | _get: function(x) { | |
479 | if(x.settableByURL !== true) | |
480 | return this.parent(x); | |
481 | ||
ea29e3d7 | 482 | var opt = this.parsedOptions.get(String(x.optionId)); |
c0f2f367 CP |
483 | if(!$defined(opt)) |
484 | return this.parent(x); | |
485 | ||
486 | return opt; | |
487 | }, | |
488 | serialise: function() { | |
489 | var result = []; | |
490 | this.getOptionList().forEach(function(x) { | |
491 | if(x.settableByURL && x.default_ != x.value) | |
10d70bfb | 492 | result.push(x.optionId + "=" + JSON.encode(x.value)); |
c0f2f367 CP |
493 | }.bind(this)); |
494 | ||
8d1217eb CP |
495 | var raw = result.join("&"); |
496 | var checksum = new qwebirc.util.crypto.MD5().digest(raw).slice(0, 2); | |
497 | return (qwebirc.util.b64Encode(raw)).replaceAll("=", "") + checksum; | |
c0f2f367 CP |
498 | } |
499 | }); | |
500 | ||
c38a0240 | 501 | qwebirc.ui.DefaultOptionsClass = new Class({ |
c0f2f367 | 502 | Extends: qwebirc.ui.SuppliedArgOptions |
c38a0240 | 503 | }); |