]>
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 on activity", true, {
18 applyChanges: function(value
, ui
) {
19 if(ui
.setBeepOnMention
)
20 ui
.setBeepOnMention(value
);
23 [16, "NOTIFICATIONS", "Emit HTML5 notifications on activity", false, {
25 if(!("Notification" in window
))
26 return [false, false]; /* [disabled, default_value] */
29 applyChanges: function(value
, ui
) {
30 if(ui
.setNotifications
)
31 ui
.setNotifications(value
);
34 [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, {
35 enabled: qwebirc
.ui
.supportsFocus
37 [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
38 [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
39 [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in channel lines", true],
40 /* 5 and 6 are reserved */
41 [8, "LASTPOS_LINE", "Show a last position indicator for each window", true, {
42 enabled: qwebirc
.ui
.supportsFocus
44 [9, "NICK_COLOURS", "Automatically colour nicknames", false],
45 [10, "HIDE_JOINPARTS", "Hide JOINS/PARTS/QUITS", false],
46 [11, "STYLE_HUE", "Adjust user interface hue", function(ui
) {
47 return {class_: qwebirc
.config
.HueOption
, default_: ui
.__styleValues
.hue
};
49 applyChanges: function(value
, ui
) {
50 ui
.setModifiableStylesheetValues({hue: value
});
53 [12, "QUERY_ON_NICK_CLICK", "Query on nickname click in channel", false],
54 [13, "SHOW_NICKLIST", "Show nickname list in channels", qwebirc
.util
.deviceHasKeyboard()],
55 [14, "SHOW_TIMESTAMPS", "Show timestamps", true], /* we rely on the hue update */
56 [15, "SIDE_TABS", "Show tabs on the side", false, {
58 if(Browser
.Engine
.trident
&& Browser
.Engine
.version
< 8)
59 return [false, false]; /* [disabled, default_value] */
62 applyChanges: function(value
, ui
) {
63 ui
.setSideTabs(value
);
68 qwebirc
.config
.QUAKENET_OPTIONS
= [
69 [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", false, {
72 [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true, {
77 qwebirc
.config
.DefaultOptions
= null;
79 qwebirc
.config
.Input
= new Class({
80 initialize: function(parent
, option
, position
, parentObject
) {
82 this.value
= option
.value
;
83 this.enabled
= this.option
.enabled
;
84 this.position
= position
;
85 this.parentElement
= parent
;
86 this.parentObject
= parentObject
;
90 createInput: function(type
, parent
, name
, selected
, id
) {
92 parent
= this.parentElement
;
94 return qwebirc
.util
.createInput(type
, parent
, name
, selected
, this.option
.id
);
96 FE: function(element
, parent
) {
97 var n
= new Element(element
);
99 parent
= this.parentElement
;
101 parent
.appendChild(n
);
105 this.mainElement
.focus();
108 this.event("render", this.mainElement
);
110 applyChanges: function() {
111 this.event("applyChanges", [this.get(), this.parentObject
.optionObject
.ui
]);
113 event: function(name
, x
) {
114 if(!$defined(this.option
.extras
))
116 var t
= this.option
.extras
[name
];
126 qwebirc
.config
.TextInput
= new Class({
127 Extends: qwebirc
.config
.Input
,
129 var i
= this.createInput("text");
130 this.mainElement
= i
;
132 i
.value
= this.value
;
133 i
.disabled
= !this.enabled
;
138 return this.mainElement
.value
;
142 qwebirc
.config
.HueInput
= new Class({
143 Extends: qwebirc
.config
.Input
,
145 var i
= new Element("div");
146 i
.addClass("qwebirc-optionspane");
147 i
.addClass("hue-slider");
148 this.parentElement
.appendChild(i
);
150 var k
= new Element("div");
152 if(Browser
.Engine
.trident
) {
153 k
.setStyle("top", "0px");
154 k
.setStyle("background-color", "black");
159 var slider
= new Slider(i
, k
, {steps: 36, range: [0, 369], wheel: true});
160 slider
.set(this.value
);
161 this.startValue
= this.value
;
163 slider
.addEvent("change", function(step
) {
167 this.mainElement
= i
;
178 this.value
= this.startValue
;
183 qwebirc
.config
.CheckInput
= new Class({
184 Extends: qwebirc
.config
.Input
,
186 var i
= this.createInput("checkbox", null, null, null, this.id
);
187 this.mainElement
= i
;
189 i
.checked
= this.value
;
190 i
.disabled
= !this.enabled
;
195 return this.mainElement
.checked
;
199 qwebirc
.config
.RadioInput
= new Class({
200 Extends: qwebirc
.config
.Input
,
202 var value
= this.option
.options
;
206 for(var i
=0;i
<value
.length
;i
++) {
207 var d
= this.FE("div", this.parentObject
);
208 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
209 this.elements
.push(e
);
210 e
.disabled
= !this.enabled
;
213 this.mainElement
= e
;
215 d
.appendChild(document
.createTextNode(value
[i
][0]));
220 for(var i
=0;i
<this.elements
.length
;i
++) {
221 var x
= this.elements
[i
];
223 this.option
.position
= i
;
224 return this.option
.options
[i
][1];
230 qwebirc
.config
.Option
= new Class({
231 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
232 this.prefix
= prefix
;
234 this.default_
= default_
;
235 this.optionId
= optionId
;
236 this.extras
= extras
;
238 if($defined(extras
) && $defined(extras
.enabled
)) {
239 var enabledResult
= extras
.enabled();
240 this.enabled
= enabledResult
[0];
242 if(!enabledResult
[0] && enabledResult
.length
> 1)
243 this.default_
= enabledResult
[1];
248 if($defined(extras
) && $defined(extras
.settableByURL
)) {
249 this.settableByURL
= extras
.settableByURL
;
251 this.settableByURL
= true;
254 setSavedValue: function(x
) {
260 qwebirc
.config
.RadioOption
= new Class({
261 Extends: qwebirc
.config
.Option
,
262 Element: qwebirc
.config
.RadioInput
,
263 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
264 this.options
= options
.map(function(x
) {
265 if(typeof(x
) == "string")
269 this.defaultposition
= default_
;
271 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
273 setSavedValue: function(x
) {
274 for(var i
=0;i
<this.options
.length
;i
++) {
275 var y
= this.options
[i
][1];
282 this.position
= this.defaultposition
;
283 this.value
= this.default_
;
287 qwebirc
.config
.TextOption
= new Class({
288 Extends: qwebirc
.config
.Option
,
289 Element: qwebirc
.config
.TextInput
292 qwebirc
.config
.CheckOption
= new Class({
293 Extends: qwebirc
.config
.Option
,
294 Element: qwebirc
.config
.CheckInput
297 qwebirc
.config
.HueOption
= new Class({
298 Extends: qwebirc
.config
.Option
,
299 Element: qwebirc
.config
.HueInput
302 qwebirc
.ui
.Options
= new Class({
303 initialize: function(ui
) {
306 if(!$defined(qwebirc
.config
.DefaultOptions
))
307 this.__configureDefaults();
309 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
310 this.optionHash
= {};
313 this.optionList
.forEach(function(x
) {
314 x
.setSavedValue(this._get(x
));
315 this.optionHash
[x
.prefix
] = x
;
316 this[x
.prefix
] = x
.value
;
319 __configureDefaults: function() {
320 var combined
= qwebirc
.config
.DEFAULT_OPTIONS
.slice(0);
323 if(this.ui
.options
.networkName
== "QuakeNet") /* HACK */
324 xo
= qwebirc
.config
.QUAKENET_OPTIONS
;
327 for(var i
=0;i
<xo
.length
;i
++)
328 combined
.push(xo
[i
]);
330 qwebirc
.config
.DefaultOptions
= combined
.map(function(x
) {
335 var moreextras
= x
[4];
338 var stype
= typeof(default_
);
339 if(stype
== "number") {
340 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
343 if(stype
== "boolean") {
344 type
= qwebirc
.config
.CheckOption
;
345 } else if(stype
== "function") {
346 var options
= default_
.call(this, this.ui
);
347 type
= options
.class_
;
348 default_
= options
.default_
;
350 type
= qwebirc
.config
.TextOption
;
352 return new type(optionId
, prefix
, label
, default_
, moreextras
);
356 setValue: function(option
, value
) {
357 this.optionHash
[option
.prefix
].value
= value
;
358 this[option
.prefix
] = value
;
360 setValueByPrefix: function(prefix
, value
) {
361 this.optionHash
[prefix
].value
= value
;
362 this[prefix
] = value
;
364 getOptionList: function() {
365 return this.optionList
;
376 qwebirc
.ui
.OptionsPane
= new Class({
377 Implements: [Events
],
378 initialize: function(parentElement
, optionObject
) {
379 this.parentElement
= parentElement
;
380 this.optionObject
= optionObject
;
382 this.createElements();
384 createElements: function() {
385 var FE = function(element
, parent
) {
386 var n
= new Element(element
);
387 parent
.appendChild(n
);
391 var t
= FE("table", this.parentElement
);
392 var tb
= FE("tbody", t
);
396 var optList
= this.optionObject
.getOptionList();
397 for(var i
=0;i
<optList
.length
;i
++) {
400 var row
= FE("tr", tb
);
401 var cella
= FE("td", row
);
403 x
.id
= qwebirc
.util
.generateID();
404 var label
= new Element("label", {"for": x
.id
});
405 cella
.appendChild(label
);
406 label
.set("text", x
.label
+ ":");
408 var cellb
= FE("td", row
);
409 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
413 var r
= FE("tr", tb
);
414 var cella
= FE("td", r
);
415 var cellb
= FE("td", r
);
416 var save
= qwebirc
.util
.createInput("submit", cellb
);
419 save
.addEvent("click", function() {
421 this.fireEvent("close");
424 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
425 cancel
.value
= "Cancel";
426 cancel
.addEvent("click", function() {
428 this.fireEvent("close");
432 this.boxList
.forEach(function(x
) {
435 this.optionObject
.setValue(option
, box
.get());
437 this.boxList
.forEach(function(x
) {
440 this.optionObject
.flush();
443 this.boxList
.forEach(function(x
) {
449 qwebirc
.ui
.CookieOptions
= new Class({
450 Extends: qwebirc
.ui
.Options
,
452 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
455 var v
= this.__cookie
.get(x
.optionId
);
462 this.__cookie
.erase();
465 this.getOptionList().forEach(function(x
) {
466 this.__cookie
.set(x
.optionId
, x
.value
);
468 this.__cookie
.save();
472 qwebirc
.ui
.SuppliedArgOptions
= new Class({
473 Extends: qwebirc
.ui
.CookieOptions
,
474 initialize: function(ui
, arg
) {
477 if($defined(arg
) && arg
!= "" && arg
.length
> 2) {
478 var checksum
= arg
.substr(arg
.length
- 2, 2);
479 var decoded
= qwebirc
.util
.b64Decode(arg
.substr(0, arg
.length
- 2));
481 if(decoded
&& (new qwebirc
.util
.crypto
.MD5().digest(decoded
).slice(0, 2) == checksum
)) {
482 var p2
= qwebirc
.util
.parseURI("?" + decoded
);
483 p2
.each(function(k
, v
) {
484 p
.put(k
, JSON
.decode(v
, true));
489 this.parsedOptions
= p
;
493 if(x
.settableByURL
!== true)
494 return this.parent(x
);
496 var opt
= this.parsedOptions
.get(String(x
.optionId
));
498 return this.parent(x
);
502 serialise: function() {
504 this.getOptionList().forEach(function(x
) {
505 if(x
.settableByURL
&& x
.default_
!= x
.value
)
506 result
.push(x
.optionId
+ "=" + JSON
.encode(x
.value
));
509 var raw
= result
.join("&");
510 var checksum
= new qwebirc
.util
.crypto
.MD5().digest(raw
).slice(0, 2);
511 return (qwebirc
.util
.b64Encode(raw
)).replaceAll("=", "") + checksum
;
515 qwebirc
.ui
.DefaultOptionsClass
= new Class({
516 Extends: qwebirc
.ui
.SuppliedArgOptions