]>
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", true, {
18 applyChanges: function(value
, ui
) {
19 if(ui
.setBeepOnMention
)
20 ui
.setBeepOnMention(value
);
23 [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, {
24 enabled: qwebirc
.ui
.supportsFocus
26 [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
27 [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
28 [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in channel lines", true],
29 [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true, {
32 [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true, {
35 [8, "LASTPOS_LINE", "Show a last position indicator for each window", true, {
36 enabled: qwebirc
.ui
.supportsFocus
38 [9, "NICK_COLOURS", "Automatically colour nicknames", false],
39 [10, "HIDE_JOINPARTS", "Hide JOINS/PARTS/QUITS", false],
40 [11, "STYLE_HUE", "Adjust user interface hue", function() {
41 return {class_: qwebirc
.config
.HueOption
, default_: 210};
43 applyChanges: function(value
, ui
) {
44 ui
.setModifiableStylesheetValues({hue: value
});
47 [12, "QUERY_ON_NICK_CLICK", "Query on nickname click in channel", false],
48 [13, "SHOW_NICKLIST", "Show nickname list in channels", true],
49 [14, "SHOW_TIMESTAMPS", "Show timestamps", true] /* we rely on the hue update */
52 qwebirc
.config
.DefaultOptions
= null;
54 qwebirc
.config
.Input
= new Class({
55 initialize: function(parent
, option
, position
, parentObject
) {
57 this.value
= option
.value
;
58 this.enabled
= this.option
.enabled
;
59 this.position
= position
;
60 this.parentElement
= parent
;
61 this.parentObject
= parentObject
;
65 createInput: function(type
, parent
, name
, selected
, id
) {
67 parent
= this.parentElement
;
69 return qwebirc
.util
.createInput(type
, parent
, name
, selected
, this.option
.id
);
71 FE: function(element
, parent
) {
72 var n
= new Element(element
);
74 parent
= this.parentElement
;
76 parent
.appendChild(n
);
80 this.mainElement
.focus();
83 this.event("render", this.mainElement
);
85 applyChanges: function() {
86 this.event("applyChanges", [this.get(), this.parentObject
.optionObject
.ui
]);
88 event: function(name
, x
) {
89 if(!$defined(this.option
.extras
))
91 var t
= this.option
.extras
[name
];
101 qwebirc
.config
.TextInput
= new Class({
102 Extends: qwebirc
.config
.Input
,
104 var i
= this.createInput("text");
105 this.mainElement
= i
;
107 i
.value
= this.value
;
108 i
.disabled
= !this.enabled
;
113 return this.mainElement
.value
;
117 qwebirc
.config
.HueInput
= new Class({
118 Extends: qwebirc
.config
.Input
,
120 var i
= new Element("div");
121 i
.addClass("qwebirc-optionspane");
122 i
.addClass("hue-slider");
123 this.parentElement
.appendChild(i
);
125 var k
= new Element("div");
127 if(Browser
.Engine
.trident
) {
128 k
.setStyle("top", "0px");
129 k
.setStyle("background-color", "black");
134 var slider
= new Slider(i
, k
, {steps: 36, range: [0, 369], wheel: true});
135 slider
.set(this.value
);
136 this.startValue
= this.value
;
138 slider
.addEvent("change", function(step
) {
142 this.mainElement
= i
;
153 this.value
= this.startValue
;
158 qwebirc
.config
.CheckInput
= new Class({
159 Extends: qwebirc
.config
.Input
,
161 var i
= this.createInput("checkbox", null, null, null, this.id
);
162 this.mainElement
= i
;
164 i
.checked
= this.value
;
165 i
.disabled
= !this.enabled
;
170 return this.mainElement
.checked
;
174 qwebirc
.config
.RadioInput
= new Class({
175 Extends: qwebirc
.config
.Input
,
177 var value
= this.option
.options
;
181 for(var i
=0;i
<value
.length
;i
++) {
182 var d
= this.FE("div", this.parentObject
);
183 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
184 this.elements
.push(e
);
185 e
.disabled
= !this.enabled
;
188 this.mainElement
= e
;
190 d
.appendChild(document
.createTextNode(value
[i
][0]));
195 for(var i
=0;i
<this.elements
.length
;i
++) {
196 var x
= this.elements
[i
];
198 this.option
.position
= i
;
199 return this.option
.options
[i
][1];
205 qwebirc
.config
.Option
= new Class({
206 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
207 this.prefix
= prefix
;
209 this.default_
= default_
;
210 this.optionId
= optionId
;
211 this.extras
= extras
;
213 if($defined(extras
) && $defined(extras
.enabled
)) {
214 var enabledResult
= extras
.enabled();
215 this.enabled
= enabledResult
[0];
217 if(!enabledResult
[0] && enabledResult
.length
> 1)
218 this.default_
= enabledResult
[1];
223 if($defined(extras
) && $defined(extras
.settableByURL
)) {
224 this.settableByURL
= extras
.settableByURL
;
226 this.settableByURL
= true;
229 setSavedValue: function(x
) {
235 qwebirc
.config
.RadioOption
= new Class({
236 Extends: qwebirc
.config
.Option
,
237 Element: qwebirc
.config
.RadioInput
,
238 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
239 this.options
= options
.map(function(x
) {
240 if(typeof(x
) == "string")
244 this.defaultposition
= default_
;
246 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
248 setSavedValue: function(x
) {
249 for(var i
=0;i
<this.options
.length
;i
++) {
250 var y
= this.options
[i
][1];
257 this.position
= this.defaultposition
;
258 this.value
= this.default_
;
262 qwebirc
.config
.TextOption
= new Class({
263 Extends: qwebirc
.config
.Option
,
264 Element: qwebirc
.config
.TextInput
267 qwebirc
.config
.CheckOption
= new Class({
268 Extends: qwebirc
.config
.Option
,
269 Element: qwebirc
.config
.CheckInput
272 qwebirc
.config
.HueOption
= new Class({
273 Extends: qwebirc
.config
.Option
,
274 Element: qwebirc
.config
.HueInput
277 qwebirc
.ui
.Options
= new Class({
278 initialize: function(ui
) {
279 if(!$defined(qwebirc
.config
.DefaultOptions
))
280 this.__configureDefaults();
282 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
287 this.optionList
.forEach(function(x
) {
288 x
.setSavedValue(this._get(x
));
289 this.optionHash
[x
.prefix
] = x
;
290 this[x
.prefix
] = x
.value
;
293 __configureDefaults: function() {
294 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
299 var moreextras
= x
[4];
302 var stype
= typeof(default_
);
303 if(stype
== "number") {
304 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
307 if(stype
== "boolean") {
308 type
= qwebirc
.config
.CheckOption
;
309 } else if(stype
== "function") {
310 var options
= default_();
311 type
= options
.class_
;
312 default_
= options
.default_
;
314 type
= qwebirc
.config
.TextOption
;
316 return new type(optionId
, prefix
, label
, default_
, moreextras
);
320 setValue: function(option
, value
) {
321 this.optionHash
[option
.prefix
].value
= value
;
322 this[option
.prefix
] = value
;
324 getOptionList: function() {
325 return this.optionList
;
336 qwebirc
.ui
.OptionsPane
= new Class({
337 Implements: [Events
],
338 initialize: function(parentElement
, optionObject
) {
339 this.parentElement
= parentElement
;
340 this.optionObject
= optionObject
;
342 this.createElements();
344 createElements: function() {
345 var FE = function(element
, parent
) {
346 var n
= new Element(element
);
347 parent
.appendChild(n
);
351 var t
= FE("table", this.parentElement
);
352 var tb
= FE("tbody", t
);
356 var optList
= this.optionObject
.getOptionList();
357 for(var i
=0;i
<optList
.length
;i
++) {
360 var row
= FE("tr", tb
);
361 var cella
= FE("td", row
);
363 x
.id
= qwebirc
.util
.generateID();
364 var label
= new Element("label", {"for": x
.id
});
365 cella
.appendChild(label
);
366 label
.set("text", x
.label
+ ":");
368 var cellb
= FE("td", row
);
369 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
373 var r
= FE("tr", tb
);
374 var cella
= FE("td", r
);
375 var cellb
= FE("td", r
);
376 var save
= qwebirc
.util
.createInput("submit", cellb
);
379 save
.addEvent("click", function() {
381 this.fireEvent("close");
384 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
385 cancel
.value
= "Cancel";
386 cancel
.addEvent("click", function() {
388 this.fireEvent("close");
392 this.boxList
.forEach(function(x
) {
395 this.optionObject
.setValue(option
, box
.get());
397 this.boxList
.forEach(function(x
) {
400 this.optionObject
.flush();
403 this.boxList
.forEach(function(x
) {
409 qwebirc
.ui
.CookieOptions
= new Class({
410 Extends: qwebirc
.ui
.Options
,
412 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
415 var v
= this.__cookie
.get(x
.optionId
);
422 this.__cookie
.erase();
425 this.getOptionList().forEach(function(x
) {
426 this.__cookie
.set(x
.optionId
, x
.value
);
428 this.__cookie
.save();
432 qwebirc
.ui
.SuppliedArgOptions
= new Class({
433 Extends: qwebirc
.ui
.CookieOptions
,
434 initialize: function(ui
, arg
) {
437 if($defined(arg
) && arg
!= "" && arg
.length
> 2) {
438 var checksum
= arg
.substr(arg
.length
- 2, 2);
439 var decoded
= qwebirc
.util
.b64Decode(arg
.substr(0, arg
.length
- 2));
441 if(decoded
&& (new qwebirc
.util
.crypto
.MD5().digest(decoded
).slice(0, 2) == checksum
)) {
442 var p2
= qwebirc
.util
.parseURI("?" + decoded
);
443 p2
.each(function(k
, v
) {
444 p
.put(k
, JSON
.decode(v
, true));
449 this.parsedOptions
= p
;
453 if(x
.settableByURL
!== true)
454 return this.parent(x
);
456 var opt
= this.parsedOptions
.get(String(x
.optionId
));
458 return this.parent(x
);
462 serialise: function() {
464 this.getOptionList().forEach(function(x
) {
465 if(x
.settableByURL
&& x
.default_
!= x
.value
)
466 result
.push(x
.optionId
+ "=" + JSON
.encode(x
.value
));
469 var raw
= result
.join("&");
470 var checksum
= new qwebirc
.util
.crypto
.MD5().digest(raw
).slice(0, 2);
471 return (qwebirc
.util
.b64Encode(raw
)).replaceAll("=", "") + checksum
;
475 qwebirc
.ui
.DefaultOptionsClass
= new Class({
476 Extends: qwebirc
.ui
.SuppliedArgOptions