]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/panes/options.js
1 qwebirc
.config
.CHECK_BOX
= 1;
2 qwebirc
.config
.TEXT_BOX
= 2;
3 qwebirc
.config
.RADIO_BUTTONS
= 3;
5 qwebirc
.config
.DEFAULT_OPTIONS
= [
6 [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity (requires Flash)", true, {
8 if(!$defined(Browser
.Plugins
.Flash
) || Browser
.Plugins
.Flash
.version
< 8)
9 return [false, false]; /* [disabled, default_value] */
12 get: function(value
, ui
) {
13 if(ui
.setBeepOnMention
)
14 ui
.setBeepOnMention(value
);
17 [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, {
19 var ua
= navigator
.userAgent
;
23 if(Browser
.Engine
.ipod
|| ua
.indexOf("Konqueror") != -1)
24 return [false, false];
29 [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
30 [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
31 [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in nicklist", true],
32 [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true],
33 [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true],
34 [8, "LASTPOS_LINE", "Show a last position indicator for each window", true]
37 qwebirc
.config
.DefaultOptions
= null;
39 qwebirc
.config
.Input
= new Class({
40 initialize: function(parent
, option
, position
, parentObject
) {
42 this.value
= option
.value
;
43 this.enabled
= this.option
.enabled
;
44 this.position
= position
;
45 this.parentElement
= parent
;
46 this.parentObject
= parentObject
;
50 createInput: function(type
, parent
, name
, selected
) {
52 parent
= this.parentElement
;
54 return qwebirc
.util
.createInput(type
, parent
, name
, selected
);
56 FE: function(element
, parent
) {
57 var n
= new Element(element
);
59 parent
= this.parentElement
;
61 parent
.appendChild(n
);
65 this.mainElement
.focus();
68 this.event("render", this.mainElement
);
70 get: function(value
) {
71 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
74 event: function(name
, x
) {
75 if(!$defined(this.option
.extras
))
77 var t
= this.option
.extras
[name
];
85 qwebirc
.config
.TextInput
= new Class({
86 Extends: qwebirc
.config
.Input
,
88 var i
= this.createInput("text");
92 i
.disabled
= !this.enabled
;
97 return this.parent(this.mainElement
.value
);
101 qwebirc
.config
.CheckInput
= new Class({
102 Extends: qwebirc
.config
.Input
,
104 var i
= this.createInput("checkbox");
105 this.mainElement
= i
;
107 i
.checked
= this.value
;
108 i
.disabled
= !this.enabled
;
113 return this.parent(this.mainElement
.checked
);
117 qwebirc
.config
.RadioInput
= new Class({
118 Extends: qwebirc
.config
.Input
,
120 var value
= this.option
.options
;
124 for(var i
=0;i
<value
.length
;i
++) {
125 var d
= this.FE("div", this.parentObject
);
126 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
127 this.elements
.push(e
);
128 e
.disabled
= !this.enabled
;
131 this.mainElement
= e
;
133 d
.appendChild(document
.createTextNode(value
[i
][0]));
138 for(var i
=0;i
<this.elements
.length
;i
++) {
139 var x
= this.elements
[i
];
141 this.option
.position
= i
;
142 return this.parent(this.option
.options
[i
][1]);
148 qwebirc
.config
.Option
= new Class({
149 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
150 this.prefix
= prefix
;
152 this.default_
= default_
;
153 this.optionId
= optionId
;
154 this.extras
= extras
;
156 if($defined(extras
) && $defined(extras
.enabled
)) {
157 var enabledResult
= extras
.enabled();
158 this.enabled
= enabledResult
[0];
160 if(!enabledResult
[0] && enabledResult
.length
> 1)
161 this.default_
= enabledResult
[1];
166 setSavedValue: function(x
) {
172 qwebirc
.config
.RadioOption
= new Class({
173 Extends: qwebirc
.config
.Option
,
174 Element: qwebirc
.config
.RadioInput
,
175 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
176 this.options
= options
.map(function(x
) {
177 if(typeof(x
) == "string")
181 this.defaultposition
= default_
;
183 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
185 setSavedValue: function(x
) {
186 for(var i
=0;i
<this.options
.length
;i
++) {
187 var y
= this.options
[i
][1];
194 this.position
= this.defaultposition
;
195 this.value
= this.default_
;
199 qwebirc
.config
.TextOption
= new Class({
200 Extends: qwebirc
.config
.Option
,
201 Element: qwebirc
.config
.TextInput
204 qwebirc
.config
.CheckOption
= new Class({
205 Extends: qwebirc
.config
.Option
,
206 Element: qwebirc
.config
.CheckInput
209 qwebirc
.ui
.Options
= new Class({
210 initialize: function(ui
) {
211 if(!$defined(qwebirc
.config
.DefaultOptions
))
212 this.__configureDefaults();
214 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
219 this.optionList
.forEach(function(x
) {
220 x
.setSavedValue(this._get(x
));
221 this.optionHash
[x
.prefix
] = x
;
222 this[x
.prefix
] = x
.value
;
225 __configureDefaults: function() {
226 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
231 var moreextras
= x
[4];
234 var stype
= typeof(default_
);
235 if(stype
== "number") {
236 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
239 if(stype
== "boolean") {
240 type
= qwebirc
.config
.CheckOption
;
242 type
= qwebirc
.config
.TextOption
;
244 return new type(optionId
, prefix
, label
, default_
, moreextras
);
248 setValue: function(option
, value
) {
249 this.optionHash
[option
.prefix
].value
= value
;
250 this[option
.prefix
] = value
;
252 getOptionList: function() {
253 return this.optionList
;
264 qwebirc
.ui
.OptionsPane
= new Class({
265 Implements: [Events
],
266 initialize: function(parentElement
, optionObject
) {
267 this.parentElement
= parentElement
;
268 this.optionObject
= optionObject
;
270 this.createElements();
272 createElements: function() {
273 var FE = function(element
, parent
) {
274 var n
= new Element(element
);
275 parent
.appendChild(n
);
279 var t
= FE("table", this.parentElement
);
280 var tb
= FE("tbody", t
);
284 var optList
= this.optionObject
.getOptionList();
285 for(var i
=0;i
<optList
.length
;i
++) {
288 var row
= FE("tr", tb
);
289 var cella
= FE("td", row
);
290 cella
.set("text", x
.label
+ ":");
292 var cellb
= FE("td", row
);
293 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
297 var r
= FE("tr", tb
);
298 var cella
= FE("td", r
);
299 var cellb
= FE("td", r
);
300 var save
= qwebirc
.util
.createInput("submit", cellb
);
303 save
.addEvent("click", function() {
305 this.fireEvent("close");
308 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
309 cancel
.value
= "Cancel";
310 cancel
.addEvent("click", function() {
311 this.fireEvent("close");
315 this.boxList
.forEach(function(x
) {
318 this.optionObject
.setValue(option
, box
.get());
320 this.optionObject
.flush();
324 qwebirc
.ui
.CookieOptions
= new Class({
325 Extends: qwebirc
.ui
.Options
,
327 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
330 var v
= this.__cookie
.get(x
.optionId
);
337 this.__cookie
.erase();
340 this.getOptionList().forEach(function(x
) {
341 this.__cookie
.set(x
.optionId
, x
.value
);
343 this.__cookie
.save();
347 qwebirc
.ui
.DefaultOptionsClass
= new Class({
348 Extends: qwebirc
.ui
.CookieOptions