-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjs.php
31 lines (26 loc) · 781 Bytes
/
js.php
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
'use strict';
function init () {
if (localStorage) {
// read opened doors
for (let k = 1; k < 25; k++) {
if (localStorage.getItem('SELFday'+k)) {
document.querySelector('li:nth-child('+k+') > a').classList.add('open');
}
}
}
const calendar = document.querySelector('ol');
calendar.addEventListener('click', saveTheDoor);
}
function saveTheDoor (event) {
const elem = event.target,
link = elem.closest('a'),
listitem = link.parentElement,
day = Array.prototype.indexOf.call(calendar.children, listitem) + 1;
if (link.classList.length == 0) {
link.classList.add('open');
if (localStorage) {
localStorage.setItem('SELFday'+day,'open');
}
}
}
document.addEventListener('DOMContentLoaded', init);