haldis/app/static/js/timer.js

37 lines
787 B
JavaScript
Raw Normal View History

2015-03-31 20:15:22 +02:00
/**
* Created by feliciaan on 30/03/15.
*/
2015-03-31 20:15:22 +02:00
$.ready(function(){
$('.time').each(function() {
var timeEl = $( this );
var time = timeEl.text().split(' ')[0].split(':');
2015-03-31 20:15:22 +02:00
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);
}
});
2015-03-31 20:15:22 +02:00
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;
}
}());