]>
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],
53 [13, "SHOW_NICKLIST", "Show nickname list in channels", true]
56 qwebirc
.config
.DefaultOptions
= null;
58 qwebirc
.config
.Input
= new Class({
59 initialize: function(parent
, option
, position
, parentObject
) {
61 this.value
= option
.value
;
62 this.enabled
= this.option
.enabled
;
63 this.position
= position
;
64 this.parentElement
= parent
;
65 this.parentObject
= parentObject
;
69 createInput: function(type
, parent
, name
, selected
, id
) {
71 parent
= this.parentElement
;
73 return qwebirc
.util
.createInput(type
, parent
, name
, selected
, this.option
.id
);
75 FE: function(element
, parent
) {
76 var n
= new Element(element
);
78 parent
= this.parentElement
;
80 parent
.appendChild(n
);
84 this.mainElement
.focus();
87 this.event("render", this.mainElement
);
89 get: function(value
) {
90 this.event("get", [value
, 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.parent(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
;
155 return this.parent(this.value
);
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.parent(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.parent(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.optionObject
.flush();
405 this.boxList
.forEach(function(x
) {
411 qwebirc
.ui
.CookieOptions
= new Class({
412 Extends: qwebirc
.ui
.Options
,
414 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
417 var v
= this.__cookie
.get(x
.optionId
);
424 this.__cookie
.erase();
427 this.getOptionList().forEach(function(x
) {
428 this.__cookie
.set(x
.optionId
, x
.value
);
430 this.__cookie
.save();
434 qwebirc
.ui
.SuppliedArgOptions
= new Class({
435 Extends: qwebirc
.ui
.CookieOptions
,
436 initialize: function(ui
, arg
) {
439 if($defined(arg
) && arg
!= "" && arg
.length
> 2) {
440 var checksum
= arg
.substr(arg
.length
- 2, 2);
441 var decoded
= qwebirc
.util
.b64Decode(arg
.substr(0, arg
.length
- 2));
443 if(decoded
&& (new qwebirc
.util
.crypto
.MD5().digest(decoded
).slice(0, 2) == checksum
)) {
444 var p2
= qwebirc
.util
.parseURI("?" + decoded
);
446 p
[k
] = JSON
.decode(p2
[k
], true);
451 this.parsedOptions
= p
;
455 if(x
.settableByURL
!== true)
456 return this.parent(x
);
458 var opt
= this.parsedOptions
[x
.optionId
];
460 return this.parent(x
);
464 serialise: function() {
466 this.getOptionList().forEach(function(x
) {
467 if(x
.settableByURL
&& x
.default_
!= x
.value
)
468 result
.push(x
.optionId
+ "=" + JSON
.encode(x
.value
));
471 var raw
= result
.join("&");
472 var checksum
= new qwebirc
.util
.crypto
.MD5().digest(raw
).slice(0, 2);
473 return (qwebirc
.util
.b64Encode(raw
)).replaceAll("=", "") + checksum
;
477 qwebirc
.ui
.DefaultOptionsClass
= new Class({
478 Extends: qwebirc
.ui
.SuppliedArgOptions