@@ -744,15 +744,23 @@ public function counter($counterSelector, $value = 0, $limit = 0, $globalName =
744
744
if (isset ($ globalName )) {
745
745
$ global = "\nwindow. {$ globalName }=interval; " ;
746
746
}
747
- $ timer = "var startTimer=function(duration, display) {var timer = duration, minutes, seconds;
747
+ $ timer = "var startTimer=function(duration, display) {var timer = duration, days, hours, minutes, seconds;
748
+ var sh=function(disp,v){if(disp.is('[value]')){disp.val(v);} else {disp.html(v);};};
749
+ var shHide=function(v,k,kBefore){if(v==0 && display.find(k).closest('.timer').is(':visible') && (!kBefore || !display.find(kBefore).closest('.timer').is(':visible'))){display.find(k).closest('.timer').hide();}else{sh(display.find(k),v);}};
750
+ var pl=function(v,text){return (v>1)?v+' '+text+'s':(v>0)?v+' '+text:'';};
751
+ var d0=function(v){return v < 10 ? '0' + v : v;};
752
+ var shortSh=function(d,h,m,s){sh(display,pl(d,'day')+' '+[h,m,s].join(':'));};
753
+ var longSh=function(d,h,m,s){shHide(d,'.day');shHide(h,'.hour','.day');shHide(m,'.minute','.hour');shHide(s,'.second','.minute');};
754
+ var mainSh=(display.find('.hour').first().length)?longSh:shortSh;
748
755
display.trigger('counter-start',timer);
749
756
display.show();
750
- var interval=setInterval(function () {
751
- minutes = parseInt(timer / 60, 10);seconds = parseInt(timer % 60, 10);
752
- minutes = minutes < 10 ? '0' + minutes : minutes;
753
- seconds = seconds < 10 ? '0' + seconds : seconds;
754
- if(display.is('[value]')){display.val(minutes + ':' + seconds);} else {display.html(minutes + ':' + seconds);};
755
- " . $ stop . "
757
+ var interval=setInterval(function () {
758
+ days = parseInt(timer / 86400, 10);
759
+ hours = d0(parseInt((timer%86400) / 3600, 10));
760
+ minutes = d0(parseInt((timer%3600) / 60, 10));
761
+ seconds = d0(parseInt(timer%60, 10));
762
+ mainSh(days,hours,minutes,seconds);
763
+ " . $ stop . "
756
764
}, 1000);
757
765
" . $ global . "
758
766
} " ;
0 commit comments