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