haldis/app/static/js/timer.js
Midgard b44d34003d
Make whitespace match convention
Convention according to our EditorConfig.
2020-02-29 17:37:33 +01:00

36 lines
787 B
JavaScript

/**
* Created by feliciaan on 30/03/15.
*/
$.ready(function(){
$('.time').each(function() {
var timeEl = $( this );
var time = timeEl.text().split(' ')[0].split(':');
if (timeEl.text().indexOf('closed') < 0) {
window.setInterval(function () {
time = my_tick(time);
if (time !== "closed") {
timeS = ("0" + time[0]).slice(-2) + ":" + ("0" + time[1]).slice(-2) + ":" + ("0" + time[2]).slice(-2) + " left";
} else {
timeS = "closed"
}
timeEl.html(timeS);
}, 1000);
}
});
function my_tick(time) {
if (time[2] > 0) {
time[2] = time[2] - 1;
} else if(time[1] > 0) {
time[2] = 59;
time[1] = time[1] - 1;
} else if(time[0] > 0) {
time[1] = 59;
time[0] = time[0] - 1;
} else {
return "closed";
}
return time;
}
}());