]>
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
.ui
.supportsFocus = function() {
6 var ua
= navigator
.userAgent
;
10 if(Browser
.Engine
.ipod
|| ua
.indexOf("Konqueror") != -1)
11 return [false, false];
16 qwebirc
.config
.DEFAULT_OPTIONS
= [
17 [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity (requires Flash)", true, {
19 if(!$defined(Browser
.Plugins
.Flash
) || Browser
.Plugins
.Flash
.version
< 8)
20 return [false, false]; /* [disabled, default_value] */
23 get: function(value
, ui
) {
24 if(ui
.setBeepOnMention
)
25 ui
.setBeepOnMention(value
);
28 [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, {
29 enabled: qwebirc
.ui
.supportsFocus
31 [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
32 [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
33 [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in nicklist", true],
34 [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true],
35 [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true],
36 [8, "LASTPOS_LINE", "Show a last position indicator for each window", true, {
37 enabled: qwebirc
.ui
.supportsFocus
39 [9, "NICK_COLOURS", "Automatically colour nicknames", false],
40 [10, "HIDE_JOINPARTS", "Hide JOINS/PARTS/QUITS", false]
43 qwebirc
.config
.DefaultOptions
= null;
45 qwebirc
.config
.Input
= new Class({
46 initialize: function(parent
, option
, position
, parentObject
) {
48 this.value
= option
.value
;
49 this.enabled
= this.option
.enabled
;
50 this.position
= position
;
51 this.parentElement
= parent
;
52 this.parentObject
= parentObject
;
56 createInput: function(type
, parent
, name
, selected
) {
58 parent
= this.parentElement
;
60 return qwebirc
.util
.createInput(type
, parent
, name
, selected
);
62 FE: function(element
, parent
) {
63 var n
= new Element(element
);
65 parent
= this.parentElement
;
67 parent
.appendChild(n
);
71 this.mainElement
.focus();
74 this.event("render", this.mainElement
);
76 get: function(value
) {
77 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
80 event: function(name
, x
) {
81 if(!$defined(this.option
.extras
))
83 var t
= this.option
.extras
[name
];
91 qwebirc
.config
.TextInput
= new Class({
92 Extends: qwebirc
.config
.Input
,
94 var i
= this.createInput("text");
98 i
.disabled
= !this.enabled
;
103 return this.parent(this.mainElement
.value
);
107 qwebirc
.config
.CheckInput
= new Class({
108 Extends: qwebirc
.config
.Input
,
110 var i
= this.createInput("checkbox");
111 this.mainElement
= i
;
113 i
.checked
= this.value
;
114 i
.disabled
= !this.enabled
;
119 return this.parent(this.mainElement
.checked
);
123 qwebirc
.config
.RadioInput
= new Class({
124 Extends: qwebirc
.config
.Input
,
126 var value
= this.option
.options
;
130 for(var i
=0;i
<value
.length
;i
++) {
131 var d
= this.FE("div", this.parentObject
);
132 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
133 this.elements
.push(e
);
134 e
.disabled
= !this.enabled
;
137 this.mainElement
= e
;
139 d
.appendChild(document
.createTextNode(value
[i
][0]));
144 for(var i
=0;i
<this.elements
.length
;i
++) {
145 var x
= this.elements
[i
];
147 this.option
.position
= i
;
148 return this.parent(this.option
.options
[i
][1]);
154 qwebirc
.config
.Option
= new Class({
155 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
156 this.prefix
= prefix
;
158 this.default_
= default_
;
159 this.optionId
= optionId
;
160 this.extras
= extras
;
162 if($defined(extras
) && $defined(extras
.enabled
)) {
163 var enabledResult
= extras
.enabled();
164 this.enabled
= enabledResult
[0];
166 if(!enabledResult
[0] && enabledResult
.length
> 1)
167 this.default_
= enabledResult
[1];
172 setSavedValue: function(x
) {
178 qwebirc
.config
.RadioOption
= new Class({
179 Extends: qwebirc
.config
.Option
,
180 Element: qwebirc
.config
.RadioInput
,
181 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
182 this.options
= options
.map(function(x
) {
183 if(typeof(x
) == "string")
187 this.defaultposition
= default_
;
189 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
191 setSavedValue: function(x
) {
192 for(var i
=0;i
<this.options
.length
;i
++) {
193 var y
= this.options
[i
][1];
200 this.position
= this.defaultposition
;
201 this.value
= this.default_
;
205 qwebirc
.config
.TextOption
= new Class({
206 Extends: qwebirc
.config
.Option
,
207 Element: qwebirc
.config
.TextInput
210 qwebirc
.config
.CheckOption
= new Class({
211 Extends: qwebirc
.config
.Option
,
212 Element: qwebirc
.config
.CheckInput
215 qwebirc
.ui
.Options
= new Class({
216 initialize: function(ui
) {
217 if(!$defined(qwebirc
.config
.DefaultOptions
))
218 this.__configureDefaults();
220 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
225 this.optionList
.forEach(function(x
) {
226 x
.setSavedValue(this._get(x
));
227 this.optionHash
[x
.prefix
] = x
;
228 this[x
.prefix
] = x
.value
;
231 __configureDefaults: function() {
232 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
237 var moreextras
= x
[4];
240 var stype
= typeof(default_
);
241 if(stype
== "number") {
242 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
245 if(stype
== "boolean") {
246 type
= qwebirc
.config
.CheckOption
;
248 type
= qwebirc
.config
.TextOption
;
250 return new type(optionId
, prefix
, label
, default_
, moreextras
);
254 setValue: function(option
, value
) {
255 this.optionHash
[option
.prefix
].value
= value
;
256 this[option
.prefix
] = value
;
258 getOptionList: function() {
259 return this.optionList
;
270 qwebirc
.ui
.OptionsPane
= new Class({
271 Implements: [Events
],
272 initialize: function(parentElement
, optionObject
) {
273 this.parentElement
= parentElement
;
274 this.optionObject
= optionObject
;
276 this.createElements();
278 createElements: function() {
279 var FE = function(element
, parent
) {
280 var n
= new Element(element
);
281 parent
.appendChild(n
);
285 var t
= FE("table", this.parentElement
);
286 var tb
= FE("tbody", t
);
290 var optList
= this.optionObject
.getOptionList();
291 for(var i
=0;i
<optList
.length
;i
++) {
294 var row
= FE("tr", tb
);
295 var cella
= FE("td", row
);
296 cella
.set("text", x
.label
+ ":");
298 var cellb
= FE("td", row
);
299 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
303 var r
= FE("tr", tb
);
304 var cella
= FE("td", r
);
305 var cellb
= FE("td", r
);
306 var save
= qwebirc
.util
.createInput("submit", cellb
);
309 save
.addEvent("click", function() {
311 this.fireEvent("close");
314 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
315 cancel
.value
= "Cancel";
316 cancel
.addEvent("click", function() {
317 this.fireEvent("close");
321 this.boxList
.forEach(function(x
) {
324 this.optionObject
.setValue(option
, box
.get());
326 this.optionObject
.flush();
330 qwebirc
.ui
.CookieOptions
= new Class({
331 Extends: qwebirc
.ui
.Options
,
333 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
336 var v
= this.__cookie
.get(x
.optionId
);
343 this.__cookie
.erase();
346 this.getOptionList().forEach(function(x
) {
347 this.__cookie
.set(x
.optionId
, x
.value
);
349 this.__cookie
.save();
353 qwebirc
.ui
.DefaultOptionsClass
= new Class({
354 Extends: qwebirc
.ui
.CookieOptions