]> iEval git - gruntmaster-page.git/blame_incremental - js/90-timers.js
Upgrade to ECMAScript 6
[gruntmaster-page.git] / js / 90-timers.js
... / ...
CommitLineData
1function 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$(() => $('.timer').each(item => {
27 update_timer(item);
28 setInterval(() => update_timer(item), 1000);
29}));
This page took 0.025929 seconds and 4 git commands to generate.