Skip to content

Commit 134d55b

Browse files
committed
Update jquery counter
1 parent 5a83346 commit 134d55b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Ajax/common/traits/JsUtilsActionsTrait.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -744,15 +744,23 @@ public function counter($counterSelector, $value = 0, $limit = 0, $globalName =
744744
if (isset($globalName)) {
745745
$global = "\nwindow.{$globalName}=interval;";
746746
}
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;
748755
display.trigger('counter-start',timer);
749756
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 . "
756764
}, 1000);
757765
" . $global . "
758766
}";

0 commit comments

Comments
 (0)