]>
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 */
50 [15, "SIDE_TABS", "Show tabs on the side", false, {
52 if(Browser
.Engine
.trident
&& Browser
.Engine
.version
< 8)
53 return [false, false]; /* [disabled, default_value] */
56 applyChanges: function(value
, ui
) {
57 ui
.setSideTabs(value
);
62 qwebirc
.config
.DefaultOptions
= null;
64 qwebirc
.config
.Input
= new Class({
65 initialize: function(parent
, option
, position
, parentObject
) {
67 this.value
= option
.value
;
68 this.enabled
= this.option
.enabled
;
69 this.position
= position
;
70 this.parentElement
= parent
;
71 this.parentObject
= parentObject
;
75 createInput: function(type
, parent
, name
, selected
, id
) {
77 parent
= this.parentElement
;
79 return qwebirc
.util
.createInput(type
, parent
, name
, selected
, this.option
.id
);
81 FE: function(element
, parent
) {
82 var n
= new Element(element
);
84 parent
= this.parentElement
;
86 parent
.appendChild(n
);
90 this.mainElement
.focus();
93 this.event("render", this.mainElement
);
95 applyChanges: function() {
96 this.event("applyChanges", [this.get(), this.parentObject
.optionObject
.ui
]);
98 event: function(name
, x
) {
99 if(!$defined(this.option
.extras
))
101 var t
= this.option
.extras
[name
];
111 qwebirc
.config
.TextInput
= new Class({
112 Extends: qwebirc
.config
.Input
,
114 var i
= this.createInput("text");
115 this.mainElement
= i
;
117 i
.value
= this.value
;
118 i
.disabled
= !this.enabled
;
123 return this.mainElement
.value
;
127 qwebirc
.config
.HueInput
= new Class({
128 Extends: qwebirc
.config
.Input
,
130 var i
= new Element("div");
131 i
.addClass("qwebirc-optionspane");
132 i
.addClass("hue-slider");
133 this.parentElement
.appendChild(i
);
135 var k
= new Element("div");
137 if(Browser
.Engine
.trident
) {
138 k
.setStyle("top", "0px");
139 k
.setStyle("background-color", "black");
144 var slider
= new Slider(i
, k
, {steps: 36, range: [0, 369], wheel: true});
145 slider
.set(this.value
);
146 this.startValue
= this.value
;
148 slider
.addEvent("change", function(step
) {
152 this.mainElement
= i
;
163 this.value
= this.startValue
;
168 qwebirc
.config
.CheckInput
= new Class({
169 Extends: qwebirc
.config
.Input
,
171 var i
= this.createInput("checkbox", null, null, null, this.id
);
172 this.mainElement
= i
;
174 i
.checked
= this.value
;
175 i
.disabled
= !this.enabled
;
180 return this.mainElement
.checked
;
184 qwebirc
.config
.RadioInput
= new Class({
185 Extends: qwebirc
.config
.Input
,
187 var value
= this.option
.options
;
191 for(var i
=0;i
<value
.length
;i
++) {
192 var d
= this.FE("div", this.parentObject
);
193 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
194 this.elements
.push(e
);
195 e
.disabled
= !this.enabled
;
198 this.mainElement
= e
;
200 d
.appendChild(document
.createTextNode(value
[i
][0]));
205 for(var i
=0;i
<this.elements
.length
;i
++) {
206 var x
= this.elements
[i
];
208 this.option
.position
= i
;
209 return this.option
.options
[i
][1];
215 qwebirc
.config
.Option
= new Class({
216 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
217 this.prefix
= prefix
;
219 this.default_
= default_
;
220 this.optionId
= optionId
;
221 this.extras
= extras
;
223 if($defined(extras
) && $defined(extras
.enabled
)) {
224 var enabledResult
= extras
.enabled();
225 this.enabled
= enabledResult
[0];
227 if(!enabledResult
[0] && enabledResult
.length
> 1)
228 this.default_
= enabledResult
[1];
233 if($defined(extras
) && $defined(extras
.settableByURL
)) {
234 this.settableByURL
= extras
.settableByURL
;
236 this.settableByURL
= true;
239 setSavedValue: function(x
) {
245 qwebirc
.config
.RadioOption
= new Class({
246 Extends: qwebirc
.config
.Option
,
247 Element: qwebirc
.config
.RadioInput
,
248 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
249 this.options
= options
.map(function(x
) {
250 if(typeof(x
) == "string")
254 this.defaultposition
= default_
;
256 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
258 setSavedValue: function(x
) {
259 for(var i
=0;i
<this.options
.length
;i
++) {
260 var y
= this.options
[i
][1];
267 this.position
= this.defaultposition
;
268 this.value
= this.default_
;
272 qwebirc
.config
.TextOption
= new Class({
273 Extends: qwebirc
.config
.Option
,
274 Element: qwebirc
.config
.TextInput
277 qwebirc
.config
.CheckOption
= new Class({
278 Extends: qwebirc
.config
.Option
,
279 Element: qwebirc
.config
.CheckInput
282 qwebirc
.config
.HueOption
= new Class({
283 Extends: qwebirc
.config
.Option
,
284 Element: qwebirc
.config
.HueInput
287 qwebirc
.ui
.Options
= new Class({
288 initialize: function(ui
) {
289 if(!$defined(qwebirc
.config
.DefaultOptions
))
290 this.__configureDefaults();
292 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
297 this.optionList
.forEach(function(x
) {
298 x
.setSavedValue(this._get(x
));
299 this.optionHash
[x
.prefix
] = x
;
300 this[x
.prefix
] = x
.value
;
303 __configureDefaults: function() {
304 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
309 var moreextras
= x
[4];
312 var stype
= typeof(default_
);
313 if(stype
== "number") {
314 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
317 if(stype
== "boolean") {
318 type
= qwebirc
.config
.CheckOption
;
319 } else if(stype
== "function") {
320 var options
= default_();
321 type
= options
.class_
;
322 default_
= options
.default_
;
324 type
= qwebirc
.config
.TextOption
;
326 return new type(optionId
, prefix
, label
, default_
, moreextras
);
330 setValue: function(option
, value
) {
331 this.optionHash
[option
.prefix
].value
= value
;
332 this[option
.prefix
] = value
;
334 getOptionList: function() {
335 return this.optionList
;
346 qwebirc
.ui
.OptionsPane
= new Class({
347 Implements: [Events
],
348 initialize: function(parentElement
, optionObject
) {
349 this.parentElement
= parentElement
;
350 this.optionObject
= optionObject
;
352 this.createElements();
354 createElements: function() {
355 var FE = function(element
, parent
) {
356 var n
= new Element(element
);
357 parent
.appendChild(n
);
361 var t
= FE("table", this.parentElement
);
362 var tb
= FE("tbody", t
);
366 var optList
= this.optionObject
.getOptionList();
367 for(var i
=0;i
<optList
.length
;i
++) {
370 var row
= FE("tr", tb
);
371 var cella
= FE("td", row
);
373 x
.id
= qwebirc
.util
.generateID();
374 var label
= new Element("label", {"for": x
.id
});
375 cella
.appendChild(label
);
376 label
.set("text", x
.label
+ ":");
378 var cellb
= FE("td", row
);
379 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
383 var r
= FE("tr", tb
);
384 var cella
= FE("td", r
);
385 var cellb
= FE("td", r
);
386 var save
= qwebirc
.util
.createInput("submit", cellb
);
389 save
.addEvent("click", function() {
391 this.fireEvent("close");
394 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
395 cancel
.value
= "Cancel";
396 cancel
.addEvent("click", function() {
398 this.fireEvent("close");
402 this.boxList
.forEach(function(x
) {
405 this.optionObject
.setValue(option
, box
.get());
407 this.boxList
.forEach(function(x
) {
410 this.optionObject
.flush();
413 this.boxList
.forEach(function(x
) {
419 qwebirc
.ui
.CookieOptions
= new Class({
420 Extends: qwebirc
.ui
.Options
,
422 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
425 var v
= this.__cookie
.get(x
.optionId
);
432 this.__cookie
.erase();
435 this.getOptionList().forEach(function(x
) {
436 this.__cookie
.set(x
.optionId
, x
.value
);
438 this.__cookie
.save();
442 qwebirc
.ui
.SuppliedArgOptions
= new Class({
443 Extends: qwebirc
.ui
.CookieOptions
,
444 initialize: function(ui
, arg
) {
447 if($defined(arg
) && arg
!= "" && arg
.length
> 2) {
448 var checksum
= arg
.substr(arg
.length
- 2, 2);
449 var decoded
= qwebirc
.util
.b64Decode(arg
.substr(0, arg
.length
- 2));
451 if(decoded
&& (new qwebirc
.util
.crypto
.MD5().digest(decoded
).slice(0, 2) == checksum
)) {
452 var p2
= qwebirc
.util
.parseURI("?" + decoded
);
453 p2
.each(function(k
, v
) {
454 p
.put(k
, JSON
.decode(v
, true));
459 this.parsedOptions
= p
;
463 if(x
.settableByURL
!== true)
464 return this.parent(x
);
466 var opt
= this.parsedOptions
.get(String(x
.optionId
));
468 return this.parent(x
);
472 serialise: function() {
474 this.getOptionList().forEach(function(x
) {
475 if(x
.settableByURL
&& x
.default_
!= x
.value
)
476 result
.push(x
.optionId
+ "=" + JSON
.encode(x
.value
));
479 var raw
= result
.join("&");
480 var checksum
= new qwebirc
.util
.crypto
.MD5().digest(raw
).slice(0, 2);
481 return (qwebirc
.util
.b64Encode(raw
)).replaceAll("=", "") + checksum
;
485 qwebirc
.ui
.DefaultOptionsClass
= new Class({
486 Extends: qwebirc
.ui
.SuppliedArgOptions