]> iEval git - gruntmaster-page.git/blob - js/90-timers.js
Depend on compiler.jar for JS compilation, move js into static/js/
[gruntmaster-page.git] / js / 90-timers.js
1 function update_timer(timer){
2 var start = parseInt(timer.dataset.start);
3 var stop = parseInt(timer.dataset.stop);
4 var value = parseInt(timer.dataset.value);
5 var now = Math.floor(Date.now() / 1000);
6
7 var left = stop - now;
8 var total = stop - start;
9 if(left < 0)
10 left = 0;
11
12 if(value) {
13 value = Math.max(value * 3 / 10, value * left / total);
14 timer.innerHTML = Math.floor(value);
15 } else {
16 var hours = left / 60 / 60;
17 hours = hours < 10 ? '0' + hours : hours;
18 var minutes = left / 60 % 60;
19 minutes = minutes < 10 ? '0' + minutes : minutes;
20 var seconds = left % 60;
21 seconds = seconds < 10 ? '0' + seconds : seconds;
22 timer.innerHTML = hours + ':' + minutes + ':' + seconds;
23 }
24 }
25
26 $(function() {
27 $('.timer').each(function(item){
28 update_timer(item);
29 setInterval(function(){update_timer(item)}, 1000);
30 });
31 });
This page took 0.0468 seconds and 4 git commands to generate.