-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.js
43 lines (38 loc) · 1.01 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @author Sergey Chikuyonok ([email protected])
* @link http://chikuyonok.ru
*/
var defaultSettings = {
'init_depth': 2,
'search.max_visible': 20,
'dnd.xpath_quote': "'",
'custom_css': '',
'intercept_requests': true
};
function loadData() {
_.each(defaultSettings, function(v, k) {
var fld = document.getElementById('fld-' + k);
if (fld.type == 'checkbox') {
fld.checked = xv_settings.getValue(k, v);
} else {
document.getElementById('fld-' + k).value = xv_settings.getValue(k, v);
}
});
}
function storeData(/* Event */ evt) {
evt.preventDefault();
_.each(defaultSettings, function(v, k) {
var input = document.getElementById('fld-' + k),
user_val = input.value;
if (input.type == 'number') {
user_val = parseInt(user_val, 10);
if (_.isNaN(user_val))
user_val = v;
} else if (input.type == 'checkbox') {
user_val = input.checked;
}
xv_settings.setValue(k, user_val);
});
}
loadData();
xv_dom.addEvent(document.getElementsByTagName('form')[0], 'submit', storeData);