-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.min.js
6 lines (6 loc) · 3.4 KB
/
index.min.js
1
2
3
4
5
6
/*!
* count-time-down@1.0.5
* A helpful countdown class, 一个实用的的倒计时类
*/
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?module.exports=s():"function"==typeof define&&define.amd?define(s):(t="undefined"!=typeof globalThis?globalThis:t||self).CountDown=s()}(this,(function(){"use strict";var t=function(t){return"function"==typeof t},s=function(t){return"number"==typeof t&&!Number.isNaN(t)&&Number.isFinite(t)};function i(i,e,h){var r,n=this;t(i)?h=i:t(e)&&(h=e),r=e,e="[object Object]"===Object.prototype.toString.call(r)?e:{},this.options=e,this.initTime=s(i)?i:null,this.restTime=this.time,this.interval=s(e.interval)?e.interval:1e3,this.autoStart=!1!==e.autoStart,this.cdType=["d","h","m","s","S"].indexOf(e.cdType)>-1?e.cdType:"h",this.running=!1,this.destoryed=!1,this.completed=!1,this.tickTimes=0,this.restDays=null,this.restHours=null,this.restMinuts=null,this.restSeconds=null,this.restMillisecond=null,this.d=null,this.h=null,this.m=null,this.s=null,this.S=null,this.dd="--",this.hh="--",this.mm="--",this.ss="--",this.SSS="---",this.ms="-:-",this.hms="-:-:-",this.mmss="--:--",this.hhmmss="--:--:--",this.timerId=null,this.start=function(){var t=this;this.destoryed||(this.running=!0,this.interval>=0&&this.restTime>=this.interval?(this.completed=!1,clearInterval(this.timerId),this.timerId=setInterval((function(){return t.tick()}),this.interval)):this.setComplete())},this.stop=function(){clearInterval(this.timerId),this.running=!1},this.destory=function(){clearInterval(this.timerId),this.running=!1,this.destoryed=!0},this.setComplete=function(){clearInterval(this.timerId),this.running=!1,this.completed=!0},this.tick=function(){this.tickTimes++,this.restTime>this.interval?(this.restTime-=this.interval,this.setValue()):(this.restTime=0,this.setValue(),this.setComplete()),t(this.onTick)&&this.onTick(this),t(h)&&h(this)},this.setValue=function(){var t=this;if((!this.restTime||this.restTime<0)&&(this.restTime=0),this.restDays=Math.floor(this.restTime/864e5),this.restHours=Math.floor(this.restTime/36e5),this.restMinuts=Math.floor(this.restTime/6e4),this.restSeconds=Math.floor(this.restTime/1e3),this.restMillisecond=this.restTime,"d"===this.cdType){var s=Math.floor(this.restTime%864e5/1e3);this.d=this.restDays,this.h=Math.floor(s/3600),this.m=Math.floor(s%3600/60),this.s=Math.floor(s%60)}else"h"===this.cdType?(this.d=0,this.h=this.restHours,this.m=Math.floor(this.restSeconds%3600/60),this.s=Math.floor(this.restSeconds%60)):"m"===this.cdType?(this.d=this.h=0,this.m=this.restMinuts,this.s=Math.floor(this.restSeconds%60)):"s"===this.cdType?(this.d=this.h=this.m=0,this.s=this.restSeconds):"S"===this.cdType&&(this.d=this.h=this.m=this.s=0,this.S=this.restMillisecond);"S"!==this.cdType&&(this.S=Math.floor(this.restTime%1e3));var i="dhmsS";i.substr(i.indexOf(this.cdType)).split("").forEach((function(s){var i=String(t[s]),e=2,h=s+s;"S"===s&&(e++,h+=s),t[h]=i.length<e?("00"+i).substr(-e):i}));var e=":";this.ms=this.m+e+this.s,this.hms=this.h+e+this.m+e+this.s,this.mmss=this.mm+e+this.ss,this.hhmmss=this.hh+e+this.mm+e+this.ss,["dd","hh","mm","ss","ms","hms","mmss","hhmmss"].forEach((function(s){t[s]=t[s].replace(/-/g,"0")}))},s(this.time)&&(this.setValue(),this.autoStart&&setTimeout((function(){return n.start()})))}return Object.defineProperty(i.prototype,"time",{get:function(){return this.initTime},set:function(t){s(t)&&(this.initTime=t,this.restTime=t)}}),i}));
//# sourceMappingURL=index.min.js.map