Added checkbox to control wether past events are shown or not
This commit is contained in:
parent
d4177e7489
commit
6bbf79e62a
@ -9,6 +9,6 @@
|
|||||||
<script src="timer.js"></script>
|
<script src="timer.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<label><input type="checkbox" id="showPastEvents" /> Auch abgelaufene Events zeigen</label>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
19
timer.js
19
timer.js
@ -54,9 +54,14 @@
|
|||||||
const countdown = document.createElement('p')
|
const countdown = document.createElement('p')
|
||||||
countdown.classList += 'countdown'
|
countdown.classList += 'countdown'
|
||||||
countdown.textContent = eventUnix - Date.now()
|
countdown.textContent = eventUnix - Date.now()
|
||||||
setInterval(() => {
|
const refresh = setInterval(() => {
|
||||||
const diff = eventUnix - Date.now()
|
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)
|
countdown.textContent = millisecondsToHumanReadable(diff)
|
||||||
|
}
|
||||||
}, 200)
|
}, 200)
|
||||||
return countdown
|
return countdown
|
||||||
}
|
}
|
||||||
@ -71,16 +76,22 @@
|
|||||||
window.document.body.appendChild(container)
|
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 = () => {
|
window.onload = () => {
|
||||||
fetchEvents().then(events => {
|
fetchEvents().then(events => {
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
events
|
events
|
||||||
.filter(event => !(window.events.showPastEvents && (Date.parse(event.date) - now < 0)))
|
|
||||||
.sort((a, b) => Date.parse(a.date) - Date.parse(b.date))
|
.sort((a, b) => Date.parse(a.date) - Date.parse(b.date))
|
||||||
.forEach(event => renderEvent(event))
|
.forEach(event => renderEvent(event))
|
||||||
})
|
})
|
||||||
|
bindLogic()
|
||||||
}
|
}
|
||||||
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|
||||||
//window.events.showPastEvents = true
|
|
Loading…
Reference in New Issue
Block a user