X-Git-Url: http://git.ieval.ro/?p=plack-app-gruntmaster.git;a=blobdiff_plain;f=js%2F90-timers.js;h=7281f6f3fd689a9d37c364ff335886660802038f;hp=6ec5bdf82a66e416e5f725d5aa3ed55e9d233080;hb=7093e9ba00cf7727a52a49d34d4df12e4f865dd4;hpb=d5bf9a1d1fc3583bc058a90ce28efeb34819744b diff --git a/js/90-timers.js b/js/90-timers.js index 6ec5bdf..7281f6f 100644 --- a/js/90-timers.js +++ b/js/90-timers.js @@ -1,35 +1,31 @@ -(function(){ - 'use strict'; +function update_timer(timer){ + var start = parseInt(timer.dataset.start); + var stop = parseInt(timer.dataset.stop); + var value = parseInt(timer.dataset.value); + var now = Math.floor(Date.now() / 1000); - function update_timer(timer){ - var start = parseInt(timer.dataset.start); - var stop = parseInt(timer.dataset.stop); - var value = parseInt(timer.dataset.value); - var now = Math.floor(Date.now() / 1000); + var left = stop - now; + var total = stop - start; + if(left < 0) + left = 0; - var left = stop - now; - var total = stop - start; - if(left < 0) - left = 0; - - if(value) { - value = Math.max(value * 3 / 10, value * left / total); - timer.innerHTML = Math.floor(value); - } else { - var hours = left / 60 / 60; - hours = hours < 10 ? '0' : hours : hours; - var minutes = left / 60 % 60; - minutes = minutes < 10 ? '0' : minutes : minutes; - var seconds = left % 60; - seconds = seconds < 10 ? '0' : seconds : seconds; - timer.innerHTML = hours + ':' + minutes + ':' + seconds; - } + if(value) { + value = Math.max(value * 3 / 10, value * left / total); + timer.innerHTML = Math.floor(value); + } else { + var hours = left / 60 / 60; + hours = hours < 10 ? '0' + hours : hours; + var minutes = left / 60 % 60; + minutes = minutes < 10 ? '0' + minutes : minutes; + var seconds = left % 60; + seconds = seconds < 10 ? '0' + seconds : seconds; + timer.innerHTML = hours + ':' + minutes + ':' + seconds; } +} - $( document ).ready(function() { - $('.timer').each(function(index, item){ - update_timer(item); - setInterval(function(){update_timer(item)}, 1000); - }); +$(function() { + $('.timer').each(function(item){ + update_timer(item); + setInterval(function(){update_timer(item)}, 1000); }); -})(); +});