From 6bbf79e62afe6117f4c5e34612cf5e2bcad47065 Mon Sep 17 00:00:00 2001 From: jreichmann Date: Mon, 11 Mar 2019 19:11:07 +0100 Subject: [PATCH] Added checkbox to control wether past events are shown or not --- index.html | 2 +- timer.js | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 01bf47c..7539c1b 100644 --- a/index.html +++ b/index.html @@ -9,6 +9,6 @@ - + \ No newline at end of file diff --git a/timer.js b/timer.js index 12b18ef..ef54465 100644 --- a/timer.js +++ b/timer.js @@ -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() - countdown.textContent = millisecondsToHumanReadable(diff) + 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 \ No newline at end of file