2020-03-05 00:37:16 +01:00
|
|
|
var haldisCountdownStart = new Date();
|
2015-03-31 20:15:22 +02:00
|
|
|
$.ready(function(){
|
2020-03-05 00:37:16 +01:00
|
|
|
$(".time").each(function() {
|
|
|
|
var timeEl = $(this);
|
|
|
|
|
|
|
|
var delta = parseInt(timeEl.data("seconds"), 10);
|
|
|
|
var end = new Date(haldisCountdownStart.getTime() + delta * 1000);
|
|
|
|
|
|
|
|
var now = new Date();
|
|
|
|
var delta = Math.floor((end - now) / 1000);
|
|
|
|
if (delta <= 0) {
|
|
|
|
timeEl.html("closed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function zeroPad(value) {
|
|
|
|
return ("0" + value).slice(-2)
|
|
|
|
}
|
|
|
|
|
|
|
|
var intervalId;
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
var now = new Date();
|
|
|
|
var delta = Math.floor((end - now) / 1000);
|
|
|
|
if (delta <= 0) {
|
|
|
|
window.clearInterval(intervalId);
|
|
|
|
if (timeEl.data("reload") === "yes") {
|
|
|
|
$("#form").slideUp();
|
|
|
|
timeEl.html("closed, refreshing page...");
|
|
|
|
window.setTimeout(function () {
|
|
|
|
window.location.reload();
|
|
|
|
}, 2000);
|
2020-02-29 17:23:20 +01:00
|
|
|
} else {
|
2020-03-05 00:37:16 +01:00
|
|
|
timeEl.html("closed");
|
2020-02-29 17:23:20 +01:00
|
|
|
}
|
2020-03-05 00:37:16 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-03-31 20:15:22 +02:00
|
|
|
|
2020-03-05 00:37:16 +01:00
|
|
|
var seconds = delta % 60;
|
|
|
|
var carry = Math.floor(delta / 60);
|
|
|
|
var minutes = carry % 60;
|
|
|
|
carry = Math.floor(carry / 60);
|
|
|
|
var hours = carry % 24;
|
|
|
|
var days = Math.floor(carry / 24);
|
|
|
|
|
|
|
|
var text = "";
|
|
|
|
if (days) text = days + " days, ";
|
|
|
|
text += zeroPad(hours) + ":" + zeroPad(minutes) + ":" + zeroPad(seconds);
|
|
|
|
text += " left";
|
|
|
|
|
|
|
|
timeEl.html(text);
|
2020-02-29 17:23:20 +01:00
|
|
|
}
|
2020-03-05 00:37:16 +01:00
|
|
|
intervalId = window.setInterval(update, 1000);
|
|
|
|
update();
|
|
|
|
});
|
2020-02-29 17:23:20 +01:00
|
|
|
}());
|