]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/panes/options.js
1 qwebirc
.ui
.supportsFocus = function() {
2 var ua
= navigator
.userAgent
;
6 if(Browser
.Engine
.ipod
|| ua
.indexOf("Konqueror") != -1)
13 * Note that options are settable by the uioptions url arg by default unless you specifiy
16 qwebirc
.config
.DEFAULT_OPTIONS
= [
17 [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity (requires Flash)", true, {
19 if(!$defined(Browser
.Plugins
.Flash
) || Browser
.Plugins
.Flash
.version
< 8)
20 return [false, false]; /* [disabled, default_value] */
23 get: function(value
, ui
) {
24 if(ui
.setBeepOnMention
)
25 ui
.setBeepOnMention(value
);
28 [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, {
29 enabled: qwebirc
.ui
.supportsFocus
31 [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
32 [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
33 [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in channel lines", true],
34 [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", false, {
37 [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true, {
40 [8, "LASTPOS_LINE", "Show a last position indicator for each window", true, {
41 enabled: qwebirc
.ui
.supportsFocus
43 [9, "NICK_COLOURS", "Automatically colour nicknames", false],
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};
48 get: function(value
, ui
) {
49 ui
.setModifiableStylesheetValues(value
, 0, 0);
52 [12, "QUERY_ON_NICK_CLICK", "Query on nickname click in channel", false]
55 qwebirc
.config
.DefaultOptions
= null;
57 qwebirc
.config
.Input
= new Class({
58 initialize: function(parent
, option
, position
, parentObject
) {
60 this.value
= option
.value
;
61 this.enabled
= this.option
.enabled
;
62 this.position
= position
;
63 this.parentElement
= parent
;
64 this.parentObject
= parentObject
;
68 createInput: function(type
, parent
, name
, selected
, id
) {
70 parent
= this.parentElement
;
72 return qwebirc
.util
.createInput(type
, parent
, name
, selected
, this.option
.id
);
74 FE: function(element
, parent
) {
75 var n
= new Element(element
);
77 parent
= this.parentElement
;
79 parent
.appendChild(n
);
83 this.mainElement
.focus();
86 this.event("render", this.mainElement
);
88 get: function(value
) {
89 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
92 event: function(name
, x
) {
93 if(!$defined(this.option
.extras
))
95 var t
= this.option
.extras
[name
];
105 qwebirc
.config
.TextInput
= new Class({
106 Extends: qwebirc
.config
.Input
,
108 var i
= this.createInput("text");
109 this.mainElement
= i
;
111 i
.value
= this.value
;
112 i
.disabled
= !this.enabled
;
117 return this.parent(this.mainElement
.value
);
121 qwebirc
.config
.HueInput
= new Class({
122 Extends: qwebirc
.config
.Input
,
124 var i
= new Element("div");
125 i
.addClass("qwebirc-optionspane");
126 i
.addClass("hue-slider");
127 this.parentElement
.appendChild(i
);
129 var k
= new Element("div");
131 if(Browser
.Engine
.trident
) {
132 k
.setStyle("top", "0px");
133 k
.setStyle("background-color", "black");
138 var slider
= new Slider(i
, k
, {steps: 36, range: [0, 369], wheel: true});
139 slider
.set(this.value
);
140 this.startValue
= this.value
;
142 slider
.addEvent("change", function(step
) {
146 this.mainElement
= i
;
154 return this.parent(this.value
);
157 this.value
= this.startValue
;
162 qwebirc
.config
.CheckInput
= new Class({
163 Extends: qwebirc
.config
.Input
,
165 var i
= this.createInput("checkbox", null, null, null, this.id
);
166 this.mainElement
= i
;
168 i
.checked
= this.value
;
169 i
.disabled
= !this.enabled
;
174 return this.parent(this.mainElement
.checked
);
178 qwebirc
.config
.RadioInput
= new Class({
179 Extends: qwebirc
.config
.Input
,
181 var value
= this.option
.options
;
185 for(var i
=0;i
<value
.length
;i
++) {
186 var d
= this.FE("div", this.parentObject
);
187 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
188 this.elements
.push(e
);
189 e
.disabled
= !this.enabled
;
192 this.mainElement
= e
;
194 d
.appendChild(document
.createTextNode(value
[i
][0]));
199 for(var i
=0;i
<this.elements
.length
;i
++) {
200 var x
= this.elements
[i
];
202 this.option
.position
= i
;
203 return this.parent(this.option
.options
[i
][1]);
209 qwebirc
.config
.Option
= new Class({
210 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
211 this.prefix
= prefix
;
213 this.default_
= default_
;
214 this.optionId
= optionId
;
215 this.extras
= extras
;
217 if($defined(extras
) && $defined(extras
.enabled
)) {
218 var enabledResult
= extras
.enabled();
219 this.enabled
= enabledResult
[0];
221 if(!enabledResult
[0] && enabledResult
.length
> 1)
222 this.default_
= enabledResult
[1];
227 if($defined(extras
) && $defined(extras
.settableByURL
)) {
228 this.settableByURL
= extras
.settableByURL
;
230 this.settableByURL
= true;
233 setSavedValue: function(x
) {
239 qwebirc
.config
.RadioOption
= new Class({
240 Extends: qwebirc
.config
.Option
,
241 Element: qwebirc
.config
.RadioInput
,
242 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
243 this.options
= options
.map(function(x
) {
244 if(typeof(x
) == "string")
248 this.defaultposition
= default_
;
250 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
252 setSavedValue: function(x
) {
253 for(var i
=0;i
<this.options
.length
;i
++) {
254 var y
= this.options
[i
][1];
261 this.position
= this.defaultposition
;
262 this.value
= this.default_
;
266 qwebirc
.config
.TextOption
= new Class({
267 Extends: qwebirc
.config
.Option
,
268 Element: qwebirc
.config
.TextInput
271 qwebirc
.config
.CheckOption
= new Class({
272 Extends: qwebirc
.config
.Option
,
273 Element: qwebirc
.config
.CheckInput
276 qwebirc
.config
.HueOption
= new Class({
277 Extends: qwebirc
.config
.Option
,
278 Element: qwebirc
.config
.HueInput
281 qwebirc
.ui
.Options
= new Class({
282 initialize: function(ui
) {
283 if(!$defined(qwebirc
.config
.DefaultOptions
))
284 this.__configureDefaults();
286 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
291 this.optionList
.forEach(function(x
) {
292 x
.setSavedValue(this._get(x
));
293 this.optionHash
[x
.prefix
] = x
;
294 this[x
.prefix
] = x
.value
;
297 __configureDefaults: function() {
298 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
303 var moreextras
= x
[4];
306 var stype
= typeof(default_
);
307 if(stype
== "number") {
308 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
311 if(stype
== "boolean") {
312 type
= qwebirc
.config
.CheckOption
;
313 } else if(stype
== "function") {
314 var options
= default_();
315 type
= options
.class_
;
316 default_
= options
.default_
;
318 type
= qwebirc
.config
.TextOption
;
320 return new type(optionId
, prefix
, label
, default_
, moreextras
);
324 setValue: function(option
, value
) {
325 this.optionHash
[option
.prefix
].value
= value
;
326 this[option
.prefix
] = value
;
328 getOptionList: function() {
329 return this.optionList
;
340 qwebirc
.ui
.OptionsPane
= new Class({
341 Implements: [Events
],
342 initialize: function(parentElement
, optionObject
) {
343 this.parentElement
= parentElement
;
344 this.optionObject
= optionObject
;
346 this.createElements();
348 createElements: function() {
349 var FE = function(element
, parent
) {
350 var n
= new Element(element
);
351 parent
.appendChild(n
);
355 var t
= FE("table", this.parentElement
);
356 var tb
= FE("tbody", t
);
360 var optList
= this.optionObject
.getOptionList();
361 for(var i
=0;i
<optList
.length
;i
++) {
364 var row
= FE("tr", tb
);
365 var cella
= FE("td", row
);
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
+ ":");
372 var cellb
= FE("td", row
);
373 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
377 var r
= FE("tr", tb
);
378 var cella
= FE("td", r
);
379 var cellb
= FE("td", r
);
380 var save
= qwebirc
.util
.createInput("submit", cellb
);
383 save
.addEvent("click", function() {
385 this.fireEvent("close");
388 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
389 cancel
.value
= "Cancel";
390 cancel
.addEvent("click", function() {
392 this.fireEvent("close");
396 this.boxList
.forEach(function(x
) {
399 this.optionObject
.setValue(option
, box
.get());
401 this.optionObject
.flush();
404 this.boxList
.forEach(function(x
) {
410 qwebirc
.ui
.CookieOptions
= new Class({
411 Extends: qwebirc
.ui
.Options
,
413 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
416 var v
= this.__cookie
.get(x
.optionId
);
423 this.__cookie
.erase();
426 this.getOptionList().forEach(function(x
) {
427 this.__cookie
.set(x
.optionId
, x
.value
);
429 this.__cookie
.save();
433 qwebirc
.ui
.SuppliedArgOptions
= new Class({
434 Extends: qwebirc
.ui
.CookieOptions
,
435 initialize: function(ui
, arg
) {
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));
442 if(decoded
&& (new qwebirc
.util
.crypto
.MD5().digest(decoded
).slice(0, 2) == checksum
))
443 p
= qwebirc
.util
.parseURI("?" + decoded
);
446 this.parsedOptions
= p
;
450 if(x
.settableByURL
!== true)
451 return this.parent(x
);
453 var opt
= this.parsedOptions
[x
.optionId
];
455 return this.parent(x
);
459 serialise: function() {
461 this.getOptionList().forEach(function(x
) {
462 if(x
.settableByURL
&& x
.default_
!= x
.value
)
463 result
.push(x
.optionId
+ "=" + x
.value
);
466 var raw
= result
.join("&");
467 var checksum
= new qwebirc
.util
.crypto
.MD5().digest(raw
).slice(0, 2);
468 return (qwebirc
.util
.b64Encode(raw
)).replaceAll("=", "") + checksum
;
472 qwebirc
.ui
.DefaultOptionsClass
= new Class({
473 Extends: qwebirc
.ui
.SuppliedArgOptions