Added checkbox to control wether past events are shown or not

This commit is contained in:
Johanna Dorothea Reichmann 2019-03-11 19:11:07 +01:00
parent d4177e7489
commit 6bbf79e62a
Signed by untrusted user who does not match committer: transcaffeine
GPG Key ID: 03624C433676E465
2 changed files with 17 additions and 6 deletions

View File

@ -9,6 +9,6 @@
<script src="timer.js"></script>
</head>
<body>
<label><input type="checkbox" id="showPastEvents" /> Auch abgelaufene Events zeigen</label>
</body>
</html>

View File

@ -54,9 +54,14 @@
const countdown = document.createElement('p')
countdown.classList += 'countdown'
countdown.textContent = eventUnix - Date.now()
setInterval(() => {
const refresh = setInterval(() => {
const diff = eventUnix - Date.now()
if ((window.events.showPastEvents && (diff < 0))) {
countdown.parentElement.style.display = 'none'
} else {
countdown.parentElement.style.display = 'block'
countdown.textContent = millisecondsToHumanReadable(diff)
}
}, 200)
return countdown
}
@ -71,16 +76,22 @@
window.document.body.appendChild(container)
}
function bindLogic() {
const checkbox = document.querySelector('#showPastEvents')
checkbox.addEventListener('change', event => {
window.events.showPastEvents = !checkbox.checked
})
checkbox.dispatchEvent(new Event('change'))
}
window.onload = () => {
fetchEvents().then(events => {
const now = Date.now()
events
.filter(event => !(window.events.showPastEvents && (Date.parse(event.date) - now < 0)))
.sort((a, b) => Date.parse(a.date) - Date.parse(b.date))
.forEach(event => renderEvent(event))
})
bindLogic()
}
})(window);
//window.events.showPastEvents = true