Skip to content

Commit

Permalink
Merge pull request #14910 from fitztrev/event-countdown-ts
Browse files Browse the repository at this point in the history
Event countdown to typescript
  • Loading branch information
ornicar committed Mar 19, 2024
2 parents c9389b8 + 95653ad commit 68c5c7e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/views/event.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object event:
views.html.base.layout(
title = e.title,
moreCss = cssTag("event"),
moreJs = iifeModule("javascripts/event-countdown.js")
moreJs = jsModule("event.countdown")
):
main(cls := "page-small event box box-pad")(
boxTop(
Expand Down
29 changes: 0 additions & 29 deletions public/javascripts/event-countdown.js

This file was deleted.

3 changes: 2 additions & 1 deletion ui/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"src/tvEmbed.ts": "tvEmbed",
"src/puzzleEmbed.ts": "puzzle.embed",
"src/lpvEmbed.ts": "lpv.embed",
"src/devMode.ts": "devMode"
"src/devMode.ts": "devMode",
"src/eventCountdown.ts": "event.countdown"
}
},
"copy": [
Expand Down
35 changes: 35 additions & 0 deletions ui/site/src/eventCountdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
site.load.then(() => {
$('.event .countdown').each(function () {
if (!this.dataset.seconds) return;

const $el = $(this);
const seconds = parseInt(this.dataset.seconds) - 1;
const target = new Date().getTime() + seconds * 1000;

const second = 1000,
minute = second * 60,
hour = minute * 60,
day = hour * 24;

const redraw = function () {
const distance = target - new Date().getTime();

if (distance > 0) {
$el.find('.days').text(Math.floor(distance / day).toString()),
$el.find('.hours').text(Math.floor((distance % day) / hour).toString()),
$el.find('.minutes').text(Math.floor((distance % hour) / minute).toString()),
$el.find('.seconds').text(
Math.floor((distance % minute) / second)
.toString()
.padStart(2, '0'),
);
} else {
clearInterval(interval);
site.reload();
}
};
const interval = setInterval(redraw, second);

redraw();
});
});

0 comments on commit 68c5c7e

Please sign in to comment.