]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/panes/options.js
402213ab0763ed1f02f2b3d025f3d28360cb7c09
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", 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 get: function(value
, ui
) {
49 ui
.setModifiableStylesheetValues(value
, 0, 0);
54 qwebirc
.config
.DefaultOptions
= null;
56 qwebirc
.config
.Input
= new Class({
57 initialize: function(parent
, option
, position
, parentObject
) {
59 this.value
= option
.value
;
60 this.enabled
= this.option
.enabled
;
61 this.position
= position
;
62 this.parentElement
= parent
;
63 this.parentObject
= parentObject
;
67 createInput: function(type
, parent
, name
, selected
) {
69 parent
= this.parentElement
;
71 return qwebirc
.util
.createInput(type
, parent
, name
, selected
);
73 FE: function(element
, parent
) {
74 var n
= new Element(element
);
76 parent
= this.parentElement
;
78 parent
.appendChild(n
);
82 this.mainElement
.focus();
85 this.event("render", this.mainElement
);
87 get: function(value
) {
88 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
91 event: function(name
, x
) {
92 if(!$defined(this.option
.extras
))
94 var t
= this.option
.extras
[name
];
104 qwebirc
.config
.TextInput
= new Class({
105 Extends: qwebirc
.config
.Input
,
107 var i
= this.createInput("text");
108 this.mainElement
= i
;
110 i
.value
= this.value
;
111 i
.disabled
= !this.enabled
;
116 return this.parent(this.mainElement
.value
);
120 qwebirc
.config
.HueInput
= new Class({
121 Extends: qwebirc
.config
.Input
,
123 var i
= new Element("div");
124 i
.addClass("qwebirc-optionspane");
125 i
.addClass("hue-slider");
126 this.parentElement
.appendChild(i
);
128 var k
= new Element("div");
130 if(Browser
.Engine
.trident
) {
131 k
.setStyle("top", "0px");
132 k
.setStyle("background-color", "black");
137 var slider
= new Slider(i
, k
, {steps: 36, range: [0, 369], wheel: true});
138 slider
.set(this.value
);
139 this.startValue
= this.value
;
141 slider
.addEvent("change", function(step
) {
145 this.mainElement
= i
;
153 return this.parent(this.value
);
156 this.value
= this.startValue
;
161 qwebirc
.config
.CheckInput
= new Class({
162 Extends: qwebirc
.config
.Input
,
164 var i
= this.createInput("checkbox");
165 this.mainElement
= i
;
167 i
.checked
= this.value
;
168 i
.disabled
= !this.enabled
;
173 return this.parent(this.mainElement
.checked
);
177 qwebirc
.config
.RadioInput
= new Class({
178 Extends: qwebirc
.config
.Input
,
180 var value
= this.option
.options
;
184 for(var i
=0;i
<value
.length
;i
++) {
185 var d
= this.FE("div", this.parentObject
);
186 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
187 this.elements
.push(e
);
188 e
.disabled
= !this.enabled
;
191 this.mainElement
= e
;
193 d
.appendChild(document
.createTextNode(value
[i
][0]));
198 for(var i
=0;i
<this.elements
.length
;i
++) {
199 var x
= this.elements
[i
];
201 this.option
.position
= i
;
202 return this.parent(this.option
.options
[i
][1]);
208 qwebirc
.config
.Option
= new Class({
209 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
210 this.prefix
= prefix
;
212 this.default_
= default_
;
213 this.optionId
= optionId
;
214 this.extras
= extras
;
216 if($defined(extras
) && $defined(extras
.enabled
)) {
217 var enabledResult
= extras
.enabled();
218 this.enabled
= enabledResult
[0];
220 if(!enabledResult
[0] && enabledResult
.length
> 1)
221 this.default_
= enabledResult
[1];
226 if($defined(extras
) && $defined(extras
.settableByURL
)) {
227 this.settableByURL
= extras
.settableByURL
;
229 this.settableByURL
= true;
232 setSavedValue: function(x
) {
238 qwebirc
.config
.RadioOption
= new Class({
239 Extends: qwebirc
.config
.Option
,
240 Element: qwebirc
.config
.RadioInput
,
241 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
242 this.options
= options
.map(function(x
) {
243 if(typeof(x
) == "string")
247 this.defaultposition
= default_
;
249 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
251 setSavedValue: function(x
) {
252 for(var i
=0;i
<this.options
.length
;i
++) {
253 var y
= this.options
[i
][1];
260 this.position
= this.defaultposition
;
261 this.value
= this.default_
;
265 qwebirc
.config
.TextOption
= new Class({
266 Extends: qwebirc
.config
.Option
,
267 Element: qwebirc
.config
.TextInput
270 qwebirc
.config
.CheckOption
= new Class({
271 Extends: qwebirc
.config
.Option
,
272 Element: qwebirc
.config
.CheckInput
275 qwebirc
.config
.HueOption
= new Class({
276 Extends: qwebirc
.config
.Option
,
277 Element: qwebirc
.config
.HueInput
280 qwebirc
.ui
.Options
= new Class({
281 initialize: function(ui
) {
282 if(!$defined(qwebirc
.config
.DefaultOptions
))
283 this.__configureDefaults();
285 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
290 this.optionList
.forEach(function(x
) {
291 x
.setSavedValue(this._get(x
));
292 this.optionHash
[x
.prefix
] = x
;
293 this[x
.prefix
] = x
.value
;
296 __configureDefaults: function() {
297 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
302 var moreextras
= x
[4];
305 var stype
= typeof(default_
);
306 if(stype
== "number") {
307 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
310 if(stype
== "boolean") {
311 type
= qwebirc
.config
.CheckOption
;
312 } else if(stype
== "function") {
313 var options
= default_();
314 type
= options
.class_
;
315 default_
= options
.default_
;
317 type
= qwebirc
.config
.TextOption
;
319 return new type(optionId
, prefix
, label
, default_
, moreextras
);
323 setValue: function(option
, value
) {
324 this.optionHash
[option
.prefix
].value
= value
;
325 this[option
.prefix
] = value
;
327 getOptionList: function() {
328 return this.optionList
;
339 qwebirc
.ui
.OptionsPane
= new Class({
340 Implements: [Events
],
341 initialize: function(parentElement
, optionObject
) {
342 this.parentElement
= parentElement
;
343 this.optionObject
= optionObject
;
345 this.createElements();
347 createElements: function() {
348 var FE = function(element
, parent
) {
349 var n
= new Element(element
);
350 parent
.appendChild(n
);
354 var t
= FE("table", this.parentElement
);
355 var tb
= FE("tbody", t
);
359 var optList
= this.optionObject
.getOptionList();
360 for(var i
=0;i
<optList
.length
;i
++) {
363 var row
= FE("tr", tb
);
364 var cella
= FE("td", row
);
365 cella
.set("text", x
.label
+ ":");
367 var cellb
= FE("td", row
);
368 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
372 var r
= FE("tr", tb
);
373 var cella
= FE("td", r
);
374 var cellb
= FE("td", r
);
375 var save
= qwebirc
.util
.createInput("submit", cellb
);
378 save
.addEvent("click", function() {
380 this.fireEvent("close");
383 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
384 cancel
.value
= "Cancel";
385 cancel
.addEvent("click", function() {
387 this.fireEvent("close");
391 this.boxList
.forEach(function(x
) {
394 this.optionObject
.setValue(option
, box
.get());
396 this.optionObject
.flush();
399 this.boxList
.forEach(function(x
) {
405 qwebirc
.ui
.CookieOptions
= new Class({
406 Extends: qwebirc
.ui
.Options
,
408 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
411 var v
= this.__cookie
.get(x
.optionId
);
418 this.__cookie
.erase();
421 this.getOptionList().forEach(function(x
) {
422 this.__cookie
.set(x
.optionId
, x
.value
);
424 this.__cookie
.save();
428 qwebirc
.ui
.SuppliedArgOptions
= new Class({
429 Extends: qwebirc
.ui
.CookieOptions
,
430 initialize: function(ui
, arg
) {
433 if($defined(arg
) && arg
!= "" && arg
.length
> 2) {
434 var checksum
= arg
.substr(arg
.length
- 2, 2);
435 var decoded
= qwebirc
.util
.b64Decode(arg
.substr(0, arg
.length
- 2));
437 if(decoded
&& (new qwebirc
.util
.crypto
.MD5().digest(decoded
).slice(0, 2) == checksum
))
438 p
= qwebirc
.util
.parseURI("?" + decoded
);
441 this.parsedOptions
= p
;
445 if(x
.settableByURL
!== true)
446 return this.parent(x
);
448 var opt
= this.parsedOptions
[x
.optionId
];
450 return this.parent(x
);
454 serialise: function() {
456 this.getOptionList().forEach(function(x
) {
457 if(x
.settableByURL
&& x
.default_
!= x
.value
)
458 result
.push(x
.optionId
+ "=" + x
.value
);
461 var raw
= result
.join("&");
462 var checksum
= new qwebirc
.util
.crypto
.MD5().digest(raw
).slice(0, 2);
463 return (qwebirc
.util
.b64Encode(raw
)).replaceAll("=", "") + checksum
;
467 qwebirc
.ui
.DefaultOptionsClass
= new Class({
468 Extends: qwebirc
.ui
.SuppliedArgOptions