aboutsummaryrefslogtreecommitdiffstats
path: root/static
diff options
context:
space:
mode:
authorGravatar Sam Wedgwood <[email protected]>2018-03-21 19:26:16 +0000
committerGravatar Joseph <[email protected]>2018-03-21 19:26:16 +0000
commitead7d4f4c5789fe2b5fa2d08175346fa8fcb24da (patch)
tree308a670bb92b4047a4e4fcfbbba37a9df1a3d762 /static
parentCopy code from API error view over to normal error views because that's the w... (diff)
Added a Code Jam Countdown (#1eevq) (#43)
* added countdown * updated jam dates * added test * flake8 * flake8 (i did it on wrong file)
Diffstat (limited to 'static')
-rw-r--r--static/js/countdown.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/static/js/countdown.js b/static/js/countdown.js
new file mode 100644
index 00000000..0992a94e
--- /dev/null
+++ b/static/js/countdown.js
@@ -0,0 +1,50 @@
+var heading = document.getElementById("countdown-title");
+var daysDisplay = document.getElementById("days");
+var hoursDisplay = document.getElementById("hours");
+var minutesDisplay = document.getElementById("minutes");
+var secondsDisplay = document.getElementById("seconds");
+var startjam = new Date(Date.UTC(2018, 2, 24));
+var endjam = new Date(Date.UTC(2018, 2, 26));
+var goal;
+var now = Date.now();
+if (now+1000 >= endjam.getTime()) {
+ heading.innerHTML = "Code Jam has finished!";
+} else {
+ if (now > startjam.getTime()) {
+ heading.innerHTML = "Code Jam ends in...";
+ goal = endjam.getTime();
+ } else {
+ heading.innerHTML = "Next Code Jam starts in...";
+ goal = startjam.getTime();
+ }
+ var refreshCountdown = setInterval(function() {
+ var delta = goal - Date.now();
+ if (delta <= 1000) {
+ clearInterval(refreshCountdown);
+ location.reload();
+ }
+ var days = Math.floor(delta / (24*60*60*1000));
+ delta -= days * (24*60*60*1000);
+ var hours = Math.floor(delta / (60*60*1000));
+ delta -= hours * (60*60*1000);
+ var minutes = Math.floor(delta / (60*1000));
+ delta -= minutes * (60*1000);
+ var seconds = Math.floor(delta / 1000);
+ if (days < 10) {
+ days = "0"+days;
+ }
+ if (hours < 10) {
+ hours = "0"+hours;
+ }
+ if (minutes < 10) {
+ minutes = "0"+minutes;
+ }
+ if (seconds < 10) {
+ seconds = "0"+seconds;
+ }
+ daysDisplay.innerHTML = days;
+ hoursDisplay.innerHTML = hours;
+ minutesDisplay.innerHTML = minutes;
+ secondsDisplay.innerHTML = seconds;
+ }, 100);
+} \ No newline at end of file