]>
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("KHTML") != -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]
36 qwebirc
.config
.DefaultOptions
= null;
38 qwebirc
.config
.Input
= new Class({
39 initialize: function(parent
, option
, position
, parentObject
) {
41 this.value
= option
.value
;
42 this.enabled
= this.option
.enabled
;
43 this.position
= position
;
44 this.parentElement
= parent
;
45 this.parentObject
= parentObject
;
49 createInput: function(type
, parent
, name
, selected
) {
51 parent
= this.parentElement
;
53 return qwebirc
.util
.createInput(type
, parent
, name
, selected
);
55 FE: function(element
, parent
) {
56 var n
= new Element(element
);
58 parent
= this.parentElement
;
60 parent
.appendChild(n
);
64 this.mainElement
.focus();
67 this.event("render", this.mainElement
);
69 get: function(value
) {
70 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
73 event: function(name
, x
) {
74 if(!$defined(this.option
.extras
))
76 var t
= this.option
.extras
[name
];
84 qwebirc
.config
.TextInput
= new Class({
85 Extends: qwebirc
.config
.Input
,
87 var i
= this.createInput("text");
91 i
.disabled
= !this.enabled
;
96 return this.parent(this.mainElement
.value
);
100 qwebirc
.config
.CheckInput
= new Class({
101 Extends: qwebirc
.config
.Input
,
103 var i
= this.createInput("checkbox");
104 this.mainElement
= i
;
106 i
.checked
= this.value
;
107 i
.disabled
= !this.enabled
;
112 return this.parent(this.mainElement
.checked
);
116 qwebirc
.config
.RadioInput
= new Class({
117 Extends: qwebirc
.config
.Input
,
119 var value
= this.option
.options
;
123 for(var i
=0;i
<value
.length
;i
++) {
124 var d
= this.FE("div", this.parentObject
);
125 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
126 this.elements
.push(e
);
127 e
.disabled
= !this.enabled
;
130 this.mainElement
= e
;
132 d
.appendChild(document
.createTextNode(value
[i
][0]));
137 for(var i
=0;i
<this.elements
.length
;i
++) {
138 var x
= this.elements
[i
];
140 this.option
.position
= i
;
141 return this.parent(this.option
.options
[i
][1]);
147 qwebirc
.config
.Option
= new Class({
148 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
149 this.prefix
= prefix
;
151 this.default_
= default_
;
152 this.optionId
= optionId
;
153 this.extras
= extras
;
155 if($defined(extras
) && $defined(extras
.enabled
)) {
156 var enabledResult
= extras
.enabled();
157 this.enabled
= enabledResult
[0];
159 if(!enabledResult
[0] && enabledResult
.length
> 1)
160 this.default_
= enabledResult
[1];
165 setSavedValue: function(x
) {
170 qwebirc
.config
.RadioOption
= new Class({
171 Extends: qwebirc
.config
.Option
,
172 Element: qwebirc
.config
.RadioInput
,
173 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
174 this.options
= options
.map(function(x
) {
175 if(typeof(x
) == "string")
179 this.defaultposition
= default_
;
181 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
183 setSavedValue: function(x
) {
184 for(var i
=0;i
<this.options
.length
;i
++) {
185 var y
= this.options
[i
][1];
192 this.position
= this.defaultposition
;
193 this.value
= this.default_
;
197 qwebirc
.config
.TextOption
= new Class({
198 Extends: qwebirc
.config
.Option
,
199 Element: qwebirc
.config
.TextInput
202 qwebirc
.config
.CheckOption
= new Class({
203 Extends: qwebirc
.config
.Option
,
204 Element: qwebirc
.config
.CheckInput
207 qwebirc
.ui
.Options
= new Class({
208 initialize: function(ui
) {
209 if(!$defined(qwebirc
.config
.DefaultOptions
))
210 this.__configureDefaults();
212 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
217 this.optionList
.forEach(function(x
) {
218 x
.setSavedValue(this._get(x
));
219 this.optionHash
[x
.prefix
] = x
;
220 this[x
.prefix
] = x
.value
;
223 __configureDefaults: function() {
224 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
229 var moreextras
= x
[4];
232 var stype
= typeof(default_
);
233 if(stype
== "number") {
234 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
237 if(stype
== "boolean") {
238 type
= qwebirc
.config
.CheckOption
;
240 type
= qwebirc
.config
.TextOption
;
242 return new type(optionId
, prefix
, label
, default_
, moreextras
);
246 setValue: function(option
, value
) {
247 this.optionHash
[option
.prefix
].value
= value
;
248 this[option
.prefix
] = value
;
250 getOptionList: function() {
251 return this.optionList
;
262 qwebirc
.ui
.OptionsPane
= new Class({
263 Implements: [Events
],
264 initialize: function(parentElement
, optionObject
) {
265 this.parentElement
= parentElement
;
266 this.optionObject
= optionObject
;
268 this.createElements();
270 createElements: function() {
271 var FE = function(element
, parent
) {
272 var n
= new Element(element
);
273 parent
.appendChild(n
);
277 var t
= FE("table", this.parentElement
);
278 var tb
= FE("tbody", t
);
282 var optList
= this.optionObject
.getOptionList();
283 for(var i
=0;i
<optList
.length
;i
++) {
286 var row
= FE("tr", tb
);
287 var cella
= FE("td", row
);
288 cella
.set("text", x
.label
+ ":");
290 var cellb
= FE("td", row
);
291 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
295 var r
= FE("tr", tb
);
296 var cella
= FE("td", r
);
297 var cellb
= FE("td", r
);
298 var save
= qwebirc
.util
.createInput("submit", cellb
);
301 save
.addEvent("click", function() {
303 this.fireEvent("close");
306 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
307 cancel
.value
= "Cancel";
308 cancel
.addEvent("click", function() {
309 this.fireEvent("close");
313 this.boxList
.forEach(function(x
) {
316 this.optionObject
.setValue(option
, box
.get());
318 this.optionObject
.flush();
322 qwebirc
.ui
.CookieOptions
= new Class({
323 Extends: qwebirc
.ui
.Options
,
325 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
328 var v
= this.__cookie
.get(x
.optionId
);
335 this.__cookie
.erase();
338 this.getOptionList().forEach(function(x
) {
339 this.__cookie
.set(x
.optionId
, x
.value
);
341 this.__cookie
.save();
345 qwebirc
.ui
.DefaultOptionsClass
= new Class({
346 Extends: qwebirc
.ui
.CookieOptions