]>
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 applyChanges: 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", true, {
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 applyChanges: function(value
, ui
) {
49 ui
.setModifiableStylesheetValues({hue: value
});
52 [12, "QUERY_ON_NICK_CLICK", "Query on nickname click in channel", false],
53 [13, "SHOW_NICKLIST", "Show nickname list in channels", true],
54 [14, "SHOW_TIMESTAMPS", "Show timestamps", true] /* we rely on the hue update */
57 qwebirc
.config
.DefaultOptions
= null;
59 qwebirc
.config
.Input
= new Class({
60 initialize: function(parent
, option
, position
, parentObject
) {
62 this.value
= option
.value
;
63 this.enabled
= this.option
.enabled
;
64 this.position
= position
;
65 this.parentElement
= parent
;
66 this.parentObject
= parentObject
;
70 createInput: function(type
, parent
, name
, selected
, id
) {
72 parent
= this.parentElement
;
74 return qwebirc
.util
.createInput(type
, parent
, name
, selected
, this.option
.id
);
76 FE: function(element
, parent
) {
77 var n
= new Element(element
);
79 parent
= this.parentElement
;
81 parent
.appendChild(n
);
85 this.mainElement
.focus();
88 this.event("render", this.mainElement
);
90 applyChanges: function() {
91 this.event("applyChanges", [this.get(), this.parentObject
.optionObject
.ui
]);
93 event: function(name
, x
) {
94 if(!$defined(this.option
.extras
))
96 var t
= this.option
.extras
[name
];
106 qwebirc
.config
.TextInput
= new Class({
107 Extends: qwebirc
.config
.Input
,
109 var i
= this.createInput("text");
110 this.mainElement
= i
;
112 i
.value
= this.value
;
113 i
.disabled
= !this.enabled
;
118 return this.mainElement
.value
;
122 qwebirc
.config
.HueInput
= new Class({
123 Extends: qwebirc
.config
.Input
,
125 var i
= new Element("div");
126 i
.addClass("qwebirc-optionspane");
127 i
.addClass("hue-slider");
128 this.parentElement
.appendChild(i
);
130 var k
= new Element("div");
132 if(Browser
.Engine
.trident
) {
133 k
.setStyle("top", "0px");
134 k
.setStyle("background-color", "black");
139 var slider
= new Slider(i
, k
, {steps: 36, range: [0, 369], wheel: true});
140 slider
.set(this.value
);
141 this.startValue
= this.value
;
143 slider
.addEvent("change", function(step
) {
147 this.mainElement
= i
;
158 this.value
= this.startValue
;
163 qwebirc
.config
.CheckInput
= new Class({
164 Extends: qwebirc
.config
.Input
,
166 var i
= this.createInput("checkbox", null, null, null, this.id
);
167 this.mainElement
= i
;
169 i
.checked
= this.value
;
170 i
.disabled
= !this.enabled
;
175 return this.mainElement
.checked
;
179 qwebirc
.config
.RadioInput
= new Class({
180 Extends: qwebirc
.config
.Input
,
182 var value
= this.option
.options
;
186 for(var i
=0;i
<value
.length
;i
++) {
187 var d
= this.FE("div", this.parentObject
);
188 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
189 this.elements
.push(e
);
190 e
.disabled
= !this.enabled
;
193 this.mainElement
= e
;
195 d
.appendChild(document
.createTextNode(value
[i
][0]));
200 for(var i
=0;i
<this.elements
.length
;i
++) {
201 var x
= this.elements
[i
];
203 this.option
.position
= i
;
204 return this.option
.options
[i
][1];
210 qwebirc
.config
.Option
= new Class({
211 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
212 this.prefix
= prefix
;
214 this.default_
= default_
;
215 this.optionId
= optionId
;
216 this.extras
= extras
;
218 if($defined(extras
) && $defined(extras
.enabled
)) {
219 var enabledResult
= extras
.enabled();
220 this.enabled
= enabledResult
[0];
222 if(!enabledResult
[0] && enabledResult
.length
> 1)
223 this.default_
= enabledResult
[1];
228 if($defined(extras
) && $defined(extras
.settableByURL
)) {
229 this.settableByURL
= extras
.settableByURL
;
231 this.settableByURL
= true;
234 setSavedValue: function(x
) {
240 qwebirc
.config
.RadioOption
= new Class({
241 Extends: qwebirc
.config
.Option
,
242 Element: qwebirc
.config
.RadioInput
,
243 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
244 this.options
= options
.map(function(x
) {
245 if(typeof(x
) == "string")
249 this.defaultposition
= default_
;
251 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
253 setSavedValue: function(x
) {
254 for(var i
=0;i
<this.options
.length
;i
++) {
255 var y
= this.options
[i
][1];
262 this.position
= this.defaultposition
;
263 this.value
= this.default_
;
267 qwebirc
.config
.TextOption
= new Class({
268 Extends: qwebirc
.config
.Option
,
269 Element: qwebirc
.config
.TextInput
272 qwebirc
.config
.CheckOption
= new Class({
273 Extends: qwebirc
.config
.Option
,
274 Element: qwebirc
.config
.CheckInput
277 qwebirc
.config
.HueOption
= new Class({
278 Extends: qwebirc
.config
.Option
,
279 Element: qwebirc
.config
.HueInput
282 qwebirc
.ui
.Options
= new Class({
283 initialize: function(ui
) {
284 if(!$defined(qwebirc
.config
.DefaultOptions
))
285 this.__configureDefaults();
287 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
292 this.optionList
.forEach(function(x
) {
293 x
.setSavedValue(this._get(x
));
294 this.optionHash
[x
.prefix
] = x
;
295 this[x
.prefix
] = x
.value
;
298 __configureDefaults: function() {
299 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
304 var moreextras
= x
[4];
307 var stype
= typeof(default_
);
308 if(stype
== "number") {
309 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
312 if(stype
== "boolean") {
313 type
= qwebirc
.config
.CheckOption
;
314 } else if(stype
== "function") {
315 var options
= default_();
316 type
= options
.class_
;
317 default_
= options
.default_
;
319 type
= qwebirc
.config
.TextOption
;
321 return new type(optionId
, prefix
, label
, default_
, moreextras
);
325 setValue: function(option
, value
) {
326 this.optionHash
[option
.prefix
].value
= value
;
327 this[option
.prefix
] = value
;
329 getOptionList: function() {
330 return this.optionList
;
341 qwebirc
.ui
.OptionsPane
= new Class({
342 Implements: [Events
],
343 initialize: function(parentElement
, optionObject
) {
344 this.parentElement
= parentElement
;
345 this.optionObject
= optionObject
;
347 this.createElements();
349 createElements: function() {
350 var FE = function(element
, parent
) {
351 var n
= new Element(element
);
352 parent
.appendChild(n
);
356 var t
= FE("table", this.parentElement
);
357 var tb
= FE("tbody", t
);
361 var optList
= this.optionObject
.getOptionList();
362 for(var i
=0;i
<optList
.length
;i
++) {
365 var row
= FE("tr", tb
);
366 var cella
= FE("td", row
);
368 x
.id
= qwebirc
.util
.generateID();
369 var label
= new Element("label", {"for": x
.id
});
370 cella
.appendChild(label
);
371 label
.set("text", x
.label
+ ":");
373 var cellb
= FE("td", row
);
374 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
378 var r
= FE("tr", tb
);
379 var cella
= FE("td", r
);
380 var cellb
= FE("td", r
);
381 var save
= qwebirc
.util
.createInput("submit", cellb
);
384 save
.addEvent("click", function() {
386 this.fireEvent("close");
389 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
390 cancel
.value
= "Cancel";
391 cancel
.addEvent("click", function() {
393 this.fireEvent("close");
397 this.boxList
.forEach(function(x
) {
400 this.optionObject
.setValue(option
, box
.get());
402 this.boxList
.forEach(function(x
) {
405 this.optionObject
.flush();
408 this.boxList
.forEach(function(x
) {
414 qwebirc
.ui
.CookieOptions
= new Class({
415 Extends: qwebirc
.ui
.Options
,
417 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
420 var v
= this.__cookie
.get(x
.optionId
);
427 this.__cookie
.erase();
430 this.getOptionList().forEach(function(x
) {
431 this.__cookie
.set(x
.optionId
, x
.value
);
433 this.__cookie
.save();
437 qwebirc
.ui
.SuppliedArgOptions
= new Class({
438 Extends: qwebirc
.ui
.CookieOptions
,
439 initialize: function(ui
, arg
) {
442 if($defined(arg
) && arg
!= "" && arg
.length
> 2) {
443 var checksum
= arg
.substr(arg
.length
- 2, 2);
444 var decoded
= qwebirc
.util
.b64Decode(arg
.substr(0, arg
.length
- 2));
446 if(decoded
&& (new qwebirc
.util
.crypto
.MD5().digest(decoded
).slice(0, 2) == checksum
)) {
447 var p2
= qwebirc
.util
.parseURI("?" + decoded
);
449 p
[k
] = JSON
.decode(p2
[k
], true);
454 this.parsedOptions
= p
;
458 if(x
.settableByURL
!== true)
459 return this.parent(x
);
461 var opt
= this.parsedOptions
[x
.optionId
];
463 return this.parent(x
);
467 serialise: function() {
469 this.getOptionList().forEach(function(x
) {
470 if(x
.settableByURL
&& x
.default_
!= x
.value
)
471 result
.push(x
.optionId
+ "=" + JSON
.encode(x
.value
));
474 var raw
= result
.join("&");
475 var checksum
= new qwebirc
.util
.crypto
.MD5().digest(raw
).slice(0, 2);
476 return (qwebirc
.util
.b64Encode(raw
)).replaceAll("=", "") + checksum
;
480 qwebirc
.ui
.DefaultOptionsClass
= new Class({
481 Extends: qwebirc
.ui
.SuppliedArgOptions