From e9ab2e5ca0d85e882bd180e9dee4b4cc5b776f33 Mon Sep 17 00:00:00 2001 From: Puneet Goyal Date: Mon, 13 May 2013 18:12:35 +0530 Subject: [PATCH 1/2] adding a resetFrom method for resetting the timer start date --- jquery.tinytimer.dev.js | 5 +++++ jquery.tinytimer.js | 2 ++ jquery.tinytimer.min.js | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jquery.tinytimer.dev.js b/jquery.tinytimer.dev.js index 2f940e7..56bb309 100644 --- a/jquery.tinytimer.dev.js +++ b/jquery.tinytimer.dev.js @@ -111,6 +111,11 @@ $.tinyTimer = function (options) { tt.paused = Date.now(); }; + /* reset the timer to another date while it is running */ + tt.resetFrom = function (newDate) { + ref = newDate; + } + tt.resume = function () { ref -= (tt.paused - Date.now()) * dir; tt.paused = 0; diff --git a/jquery.tinytimer.js b/jquery.tinytimer.js index 5f5a2a5..28177be 100644 --- a/jquery.tinytimer.js +++ b/jquery.tinytimer.js @@ -33,6 +33,8 @@ ref -= (tt.paused - Date.now()) * dir, tt.paused = 0; }, tt.start = function() { tt.paused = 0; + }, tt.resetFrom = function(newDate) { + ref = newDate; }; }, $.fn.tinyTimer = function(options) { return this.each(function() { diff --git a/jquery.tinytimer.min.js b/jquery.tinytimer.min.js index 51b76cf..622bb30 100644 --- a/jquery.tinytimer.min.js +++ b/jquery.tinytimer.min.js @@ -1 +1 @@ -/*! tinytimer 0.1.4 */ (function(t){t.tinyTimer=function(e){var n,a=this,i=(a.options=e).element,o=new Date(e.from||e.to).getTime(),r=!!e.from||-1,u=Math,s=function(){};a.interval=setInterval(n=function(){if(!a.paused){var n=u.max(u.round((Date.now()-o)*r/1e3),0),l={S:n,s:n%60,M:u.floor(n/=60),H:u.floor(n/=60),D:u.floor(n/=24)};l.m=l.M%60,l.h=l.H%24,l.d=l.D,l.text=(e.format||"%-H{:}%0m:%0s").replace(/%(-?)(0?)([dhms])(\s*)(?:\{(.+?)\})?/gi,e.replacer||function(t,e,n,a,i,o){var r=l[a];return(o=(o||"").split("|"))[2]=o[2]||(o[1]=o[1]||o[0]),!r&&e?"":(r>9?"":n)+r+i+o[+(1!=r)+(1!=r&&(2>r%10||r%10>4)||r>10&&20>r)]}),i?t(i).html(l.text):i=a,(e.onTick||s).call(i,a.val=l),0>r&&!n&&(clearInterval(a.interval),(e.onEnd||s).call(i,l))}},1e3),n(),a.pause=a.stop=function(){a.paused=Date.now()},a.resume=function(){o-=(a.paused-Date.now())*r,a.paused=0},a.start=function(){a.paused=0}},t.fn.tinyTimer=function(e){return this.each(function(){t(this).data("tinyTimer",new t.tinyTimer(t.extend(e,{element:t(this)})))})}})(jQuery); \ No newline at end of file +/*! tinytimer 0.1.4 */(function(a){a.tinyTimer=function(b){var c,d=this,e=(d.options=b).element,f=new Date(b.from||b.to).getTime(),g=!!b.from||-1,h=Math,i=function(){};d.interval=setInterval(c=function(){if(!d.paused){var c=h.max(h.round((Date.now()-f)*g/1e3),0),j={S:c,s:c%60,M:h.floor(c/=60),H:h.floor(c/=60),D:h.floor(c/=24)};j.m=j.M%60,j.h=j.H%24,j.d=j.D,j.text=(b.format||"%-H{:}%0m:%0s").replace(/%(-?)(0?)([dhms])(\s*)(?:\{(.+?)\})?/gi,b.replacer||function(a,b,c,d,e,f){var g=j[d];return(f=(f||"").split("|"))[2]=f[2]||(f[1]=f[1]||f[0]),!g&&b?"":(g>9?"":c)+g+e+f[+(1!=g)+(1!=g&&(2>g%10||g%10>4)||g>10&&20>g)]}),e?a(e).html(j.text):e=d,(b.onTick||i).call(e,d.val=j),0>g&&!c&&(clearInterval(d.interval),(b.onEnd||i).call(e,j))}},1e3),c(),d.pause=d.stop=function(){d.paused=Date.now()},d.resume=function(){f-=(d.paused-Date.now())*g,d.paused=0},d.start=function(){d.paused=0},d.resetFrom=function(a){f=a}},a.fn.tinyTimer=function(b){return this.each(function(){a(this).data("tinyTimer",new a.tinyTimer(a.extend(b,{element:a(this)})))})}})(jQuery); \ No newline at end of file From aba1de5650c1d05e18a857c73701b636976e262f Mon Sep 17 00:00:00 2001 From: Puneet Goyal Date: Mon, 13 May 2013 18:15:50 +0530 Subject: [PATCH 2/2] better uglified code --- jquery.tinytimer.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.tinytimer.min.js b/jquery.tinytimer.min.js index 622bb30..d4fdad2 100644 --- a/jquery.tinytimer.min.js +++ b/jquery.tinytimer.min.js @@ -1 +1 @@ -/*! tinytimer 0.1.4 */(function(a){a.tinyTimer=function(b){var c,d=this,e=(d.options=b).element,f=new Date(b.from||b.to).getTime(),g=!!b.from||-1,h=Math,i=function(){};d.interval=setInterval(c=function(){if(!d.paused){var c=h.max(h.round((Date.now()-f)*g/1e3),0),j={S:c,s:c%60,M:h.floor(c/=60),H:h.floor(c/=60),D:h.floor(c/=24)};j.m=j.M%60,j.h=j.H%24,j.d=j.D,j.text=(b.format||"%-H{:}%0m:%0s").replace(/%(-?)(0?)([dhms])(\s*)(?:\{(.+?)\})?/gi,b.replacer||function(a,b,c,d,e,f){var g=j[d];return(f=(f||"").split("|"))[2]=f[2]||(f[1]=f[1]||f[0]),!g&&b?"":(g>9?"":c)+g+e+f[+(1!=g)+(1!=g&&(2>g%10||g%10>4)||g>10&&20>g)]}),e?a(e).html(j.text):e=d,(b.onTick||i).call(e,d.val=j),0>g&&!c&&(clearInterval(d.interval),(b.onEnd||i).call(e,j))}},1e3),c(),d.pause=d.stop=function(){d.paused=Date.now()},d.resume=function(){f-=(d.paused-Date.now())*g,d.paused=0},d.start=function(){d.paused=0},d.resetFrom=function(a){f=a}},a.fn.tinyTimer=function(b){return this.each(function(){a(this).data("tinyTimer",new a.tinyTimer(a.extend(b,{element:a(this)})))})}})(jQuery); \ No newline at end of file +/*! tinytimer 0.1.4 */(function(t){t.tinyTimer=function(e){var n,i=this,o=(i.options=e).element,r=new Date(e.from||e.to).getTime(),a=!!e.from||-1,u=Math,s=function(){};i.interval=setInterval(n=function(){if(!i.paused){var n=u.max(u.round((Date.now()-r)*a/1e3),0),f={S:n,s:n%60,M:u.floor(n/=60),H:u.floor(n/=60),D:u.floor(n/=24)};f.m=f.M%60,f.h=f.H%24,f.d=f.D,f.text=(e.format||"%-H{:}%0m:%0s").replace(/%(-?)(0?)([dhms])(\s*)(?:\{(.+?)\})?/gi,e.replacer||function(t,e,n,i,o,r){var a=f[i];return(r=(r||"").split("|"))[2]=r[2]||(r[1]=r[1]||r[0]),!a&&e?"":(a>9?"":n)+a+o+r[+(1!=a)+(1!=a&&(2>a%10||a%10>4)||a>10&&20>a)]}),o?t(o).html(f.text):o=i,(e.onTick||s).call(o,i.val=f),0>a&&!n&&(clearInterval(i.interval),(e.onEnd||s).call(o,f))}},1e3),n(),i.pause=i.stop=function(){i.paused=Date.now()},i.resetFrom=function(t){r=t},i.resume=function(){r-=(i.paused-Date.now())*a,i.paused=0},i.start=function(){i.paused=0}},t.fn.tinyTimer=function(e){return this.each(function(){t(this).data("tinyTimer",new t.tinyTimer(t.extend(e,{element:t(this)})))})}})(jQuery) \ No newline at end of file