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