Get rid of sprintf
[plack-app-gruntmaster.git] / js / 90-timers.js
1 (function(){
2 'use strict';
3
4 function update_timer(timer){
5 var start = parseInt(timer.dataset.start);
6 var stop = parseInt(timer.dataset.stop);
7 var value = parseInt(timer.dataset.value);
8 var now = Math.floor(Date.now() / 1000);
9
10 var left = stop - now;
11 var total = stop - start;
12 if(left < 0)
13 left = 0;
14
15 if(value) {
16 value = Math.max(value * 3 / 10, value * left / total);
17 timer.innerHTML = Math.floor(value);
18 } else {
19 var hours = left / 60 / 60;
20 hours = hours < 10 ? '0' : hours : hours;
21 var minutes = left / 60 % 60;
22 minutes = minutes < 10 ? '0' : minutes : minutes;
23 var seconds = left % 60;
24 seconds = seconds < 10 ? '0' : seconds : seconds;
25 timer.innerHTML = hours + ':' + minutes + ':' + seconds;
26 }
27 }
28
29 $( document ).ready(function() {
30 $('.timer').each(function(index, item){
31 update_timer(item);
32 setInterval(function(){update_timer(item)}, 1000);
33 });
34 });
35 })();
This page took 0.022203 seconds and 4 git commands to generate.