]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/panes/options.js
251b01d60ef0a4c8eb395111755289717f9cfc3a
1 qwebirc
.ui
.supportsFocus = function() {
2 var ua
= navigator
.userAgent
;
6 if(Browser
.Engine
.ipod
|| ua
.indexOf("Konqueror") != -1)
12 qwebirc
.config
.DEFAULT_OPTIONS
= [
13 [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity (requires Flash)", true, {
15 if(!$defined(Browser
.Plugins
.Flash
) || Browser
.Plugins
.Flash
.version
< 8)
16 return [false, false]; /* [disabled, default_value] */
19 get: function(value
, ui
) {
20 if(ui
.setBeepOnMention
)
21 ui
.setBeepOnMention(value
);
24 [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, {
25 enabled: qwebirc
.ui
.supportsFocus
27 [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
28 [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
29 [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in channel lines", true],
30 [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true],
31 [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true],
32 [8, "LASTPOS_LINE", "Show a last position indicator for each window", true, {
33 enabled: qwebirc
.ui
.supportsFocus
35 [9, "NICK_COLOURS", "Automatically colour nicknames", false],
36 [10, "HIDE_JOINPARTS", "Hide JOINS/PARTS/QUITS", false],
37 [11, "STYLE_HUE", "Adjust user interface hue", function() {
38 return {class_: qwebirc
.config
.HueOption
, default_: 210};
40 get: function(value
, ui
) {
41 ui
.setModifiableStylesheetValues(value
, 0, 0);
46 qwebirc
.config
.DefaultOptions
= null;
48 qwebirc
.config
.Input
= new Class({
49 initialize: function(parent
, option
, position
, parentObject
) {
51 this.value
= option
.value
;
52 this.enabled
= this.option
.enabled
;
53 this.position
= position
;
54 this.parentElement
= parent
;
55 this.parentObject
= parentObject
;
59 createInput: function(type
, parent
, name
, selected
) {
61 parent
= this.parentElement
;
63 return qwebirc
.util
.createInput(type
, parent
, name
, selected
);
65 FE: function(element
, parent
) {
66 var n
= new Element(element
);
68 parent
= this.parentElement
;
70 parent
.appendChild(n
);
74 this.mainElement
.focus();
77 this.event("render", this.mainElement
);
79 get: function(value
) {
80 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
83 event: function(name
, x
) {
84 if(!$defined(this.option
.extras
))
86 var t
= this.option
.extras
[name
];
96 qwebirc
.config
.TextInput
= new Class({
97 Extends: qwebirc
.config
.Input
,
99 var i
= this.createInput("text");
100 this.mainElement
= i
;
102 i
.value
= this.value
;
103 i
.disabled
= !this.enabled
;
108 return this.parent(this.mainElement
.value
);
112 qwebirc
.config
.HueInput
= new Class({
113 Extends: qwebirc
.config
.Input
,
115 var i
= new Element("div");
116 i
.addClass("qwebirc-optionspane");
117 i
.addClass("hue-slider");
118 this.parentElement
.appendChild(i
);
120 var k
= new Element("div");
122 if(Browser
.Engine
.trident
) {
123 k
.setStyle("top", "0px");
124 k
.setStyle("background-color", "black");
129 var slider
= new Slider(i
, k
, {steps: 36, range: [0, 369], wheel: true});
130 slider
.set(this.value
);
131 this.startValue
= this.value
;
133 slider
.addEvent("change", function(step
) {
137 this.mainElement
= i
;
145 return this.parent(this.value
);
148 this.value
= this.startValue
;
153 qwebirc
.config
.CheckInput
= new Class({
154 Extends: qwebirc
.config
.Input
,
156 var i
= this.createInput("checkbox");
157 this.mainElement
= i
;
159 i
.checked
= this.value
;
160 i
.disabled
= !this.enabled
;
165 return this.parent(this.mainElement
.checked
);
169 qwebirc
.config
.RadioInput
= new Class({
170 Extends: qwebirc
.config
.Input
,
172 var value
= this.option
.options
;
176 for(var i
=0;i
<value
.length
;i
++) {
177 var d
= this.FE("div", this.parentObject
);
178 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
179 this.elements
.push(e
);
180 e
.disabled
= !this.enabled
;
183 this.mainElement
= e
;
185 d
.appendChild(document
.createTextNode(value
[i
][0]));
190 for(var i
=0;i
<this.elements
.length
;i
++) {
191 var x
= this.elements
[i
];
193 this.option
.position
= i
;
194 return this.parent(this.option
.options
[i
][1]);
200 qwebirc
.config
.Option
= new Class({
201 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
202 this.prefix
= prefix
;
204 this.default_
= default_
;
205 this.optionId
= optionId
;
206 this.extras
= extras
;
208 if($defined(extras
) && $defined(extras
.enabled
)) {
209 var enabledResult
= extras
.enabled();
210 this.enabled
= enabledResult
[0];
212 if(!enabledResult
[0] && enabledResult
.length
> 1)
213 this.default_
= enabledResult
[1];
218 setSavedValue: function(x
) {
224 qwebirc
.config
.RadioOption
= new Class({
225 Extends: qwebirc
.config
.Option
,
226 Element: qwebirc
.config
.RadioInput
,
227 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
228 this.options
= options
.map(function(x
) {
229 if(typeof(x
) == "string")
233 this.defaultposition
= default_
;
235 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
237 setSavedValue: function(x
) {
238 for(var i
=0;i
<this.options
.length
;i
++) {
239 var y
= this.options
[i
][1];
246 this.position
= this.defaultposition
;
247 this.value
= this.default_
;
251 qwebirc
.config
.TextOption
= new Class({
252 Extends: qwebirc
.config
.Option
,
253 Element: qwebirc
.config
.TextInput
256 qwebirc
.config
.CheckOption
= new Class({
257 Extends: qwebirc
.config
.Option
,
258 Element: qwebirc
.config
.CheckInput
261 qwebirc
.config
.HueOption
= new Class({
262 Extends: qwebirc
.config
.Option
,
263 Element: qwebirc
.config
.HueInput
266 qwebirc
.ui
.Options
= new Class({
267 initialize: function(ui
) {
268 if(!$defined(qwebirc
.config
.DefaultOptions
))
269 this.__configureDefaults();
271 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
276 this.optionList
.forEach(function(x
) {
277 x
.setSavedValue(this._get(x
));
278 this.optionHash
[x
.prefix
] = x
;
279 this[x
.prefix
] = x
.value
;
282 __configureDefaults: function() {
283 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
288 var moreextras
= x
[4];
291 var stype
= typeof(default_
);
292 if(stype
== "number") {
293 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
296 if(stype
== "boolean") {
297 type
= qwebirc
.config
.CheckOption
;
298 } else if(stype
== "function") {
299 var options
= default_();
300 type
= options
.class_
;
301 default_
= options
.default_
;
303 type
= qwebirc
.config
.TextOption
;
305 return new type(optionId
, prefix
, label
, default_
, moreextras
);
309 setValue: function(option
, value
) {
310 this.optionHash
[option
.prefix
].value
= value
;
311 this[option
.prefix
] = value
;
313 getOptionList: function() {
314 return this.optionList
;
325 qwebirc
.ui
.OptionsPane
= new Class({
326 Implements: [Events
],
327 initialize: function(parentElement
, optionObject
) {
328 this.parentElement
= parentElement
;
329 this.optionObject
= optionObject
;
331 this.createElements();
333 createElements: function() {
334 var FE = function(element
, parent
) {
335 var n
= new Element(element
);
336 parent
.appendChild(n
);
340 var t
= FE("table", this.parentElement
);
341 var tb
= FE("tbody", t
);
345 var optList
= this.optionObject
.getOptionList();
346 for(var i
=0;i
<optList
.length
;i
++) {
349 var row
= FE("tr", tb
);
350 var cella
= FE("td", row
);
351 cella
.set("text", x
.label
+ ":");
353 var cellb
= FE("td", row
);
354 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
358 var r
= FE("tr", tb
);
359 var cella
= FE("td", r
);
360 var cellb
= FE("td", r
);
361 var save
= qwebirc
.util
.createInput("submit", cellb
);
364 save
.addEvent("click", function() {
366 this.fireEvent("close");
369 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
370 cancel
.value
= "Cancel";
371 cancel
.addEvent("click", function() {
373 this.fireEvent("close");
377 this.boxList
.forEach(function(x
) {
380 this.optionObject
.setValue(option
, box
.get());
382 this.optionObject
.flush();
385 this.boxList
.forEach(function(x
) {
391 qwebirc
.ui
.CookieOptions
= new Class({
392 Extends: qwebirc
.ui
.Options
,
394 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
397 var v
= this.__cookie
.get(x
.optionId
);
404 this.__cookie
.erase();
407 this.getOptionList().forEach(function(x
) {
408 this.__cookie
.set(x
.optionId
, x
.value
);
410 this.__cookie
.save();
414 qwebirc
.ui
.DefaultOptionsClass
= new Class({
415 Extends: qwebirc
.ui
.CookieOptions