-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathactions.js
34 lines (32 loc) · 973 Bytes
/
actions.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
function checkLocalStorage() {
var test = 'test';
try {
localStorage.setItem(test, test);
localStorage.removeItem(test);
return true;
} catch(e) {
return false;
}
}
var localStorageAvailable = checkLocalStorage();
function storeActionDone(event) {
if (event.target.checked) {
localStorage.setItem(event.target.name, 'done');
} else {
localStorage.removeItem(event.target.name);
}
}
if (localStorageAvailable) {
var actions = window.checkableActions;
for (var i = 0; i < actions.length; ++i) {
var check_id = actions[i] + '/check';
var checkboxes = document.getElementsByName(check_id);
for (var j = 0; j < checkboxes.length; ++j) {
var checkbox = checkboxes[j];
if (localStorage.getItem(check_id)) {
checkbox.checked = true;
}
checkbox.addEventListener('change', storeActionDone);
}
}
}