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