-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathpopup.js
48 lines (45 loc) · 1.74 KB
/
popup.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
44
45
46
47
48
const optionsMapping = {enableOption: ENABLE_OPTION, showBreedsStats: SHOW_BREEDS_STATS_OPTION};
$(document).ready(function(){
let options = Object.keys(optionsMapping);
getOptions(function(response) {
let storedOpts = response;
if (Object.keys(storedOpts).length != options.length) {
storedOpts = resetOptions();
}
for (let opt in optionsMapping) {
//set UI
if (storedOpts[optionsMapping[opt]]) {
$("#" + opt).prop('checked', true);
} else {
$("#" + opt).prop('checked', false);
}
if (!storedOpts[ENABLE_OPTION] && opt != "enableOption") {
$("#" + opt).prop('disabled', true);
}
//handle future changes
if (opt == "enableOption") {
$("#" + opt).click(function() {
if( $(this).is(':checked') ) {
putOption(optionsMapping[opt], true);
for (let opt in optionsMapping) {
$("#" + opt).prop('disabled', false);
}
} else {
putOption(optionsMapping[opt], false);
for (let opt in optionsMapping) {
$("#" + opt).prop('disabled', true);
}
}
});
} else {
$("#" + opt).click(function() {
if( $(this).is(':checked') ) {
putOption(optionsMapping[opt], true);
} else {
putOption(optionsMapping[opt], false);
}
});
}
}
});
});