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