]> iEval git - gruntmaster-page.git/blob - js/90-timers.js
Update bootswatch to 3.3.4
[gruntmaster-page.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 var minutes = left / 60 % 60;
21 var seconds = left % 60;
22 timer.innerHTML = sprintf('%02d:%02d:%02d', hours, minutes, seconds);
23 }
24 }
25
26 $( document ).ready(function() {
27 $('.timer').each(function(index, item){
28 update_timer(item);
29 setInterval(function(){update_timer(item)}, 1000);
30 });
31 });
32 })();
This page took 0.06116 seconds and 4 git commands to generate.