forked from iwayanwirka/dscountdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dscountdown.min.js
7 lines (7 loc) · 3.58 KB
/
dscountdown.min.js
1
2
3
4
5
6
7
/*!
dsCountDown v1.1
jQuery count down plugin
(c) 2013 I Wayan Wirka - http://iwayanwirka.duststone.com/dscountdown/
license: http://www.opensource.org/licenses/mit-license.php
*/
(function(e){e.fn.dsCountDown=function(t){var n=this;n.data={refreshed:1e3,thread:null,running:false,left:0,decreament:1,interval:0,seconds:0,minutes:0,hours:0,days:0,elemDays:null,elemHours:null,elemMinutes:null,elemSeconds:null};var r={startDate:new Date,endDate:null,elemSelDays:"",elemSelHours:"",elemSelMinutes:"",elemSelSeconds:"",theme:"white",titleDays:"Days",titleHours:"Hours",titleMinutes:"Minutes",titleSeconds:"Seconds",onBevoreStart:null,onClocking:null,onFinish:null};n.options=e.extend({},r,t);if(this.length>1){this.each(function(){e(this).dsCountDown(t)});return this}n.init=function(){if(!n.options.elemSelSeconds){n.prepend('<div class="ds-element ds-element-seconds"> <div class="ds-element-title">'+n.options.titleSeconds+'</div> <div class="ds-element-value ds-seconds">00</div> </div>');n.data.elemSeconds=n.find(".ds-seconds")}else{n.data.elemSeconds=n.find(n.options.elemSelSeconds)}if(!n.options.elemSelMinutes){n.prepend('<div class="ds-element ds-element-minutes"> <div class="ds-element-title">'+n.options.titleMinutes+'</div> <div class="ds-element-value ds-minutes">00</div> </div>');n.data.elemMinutes=n.find(".ds-minutes")}else{n.data.elemMinutes=n.find(n.options.elemSelMinutes)}if(!n.options.elemSelHours){n.prepend('<div class="ds-element ds-element-hours"> <div class="ds-element-title">'+n.options.titleHours+'</div> <div class="ds-element-value ds-hours">00</div> </div>');n.data.elemHours=n.find(".ds-hours")}else{n.data.elemHours=n.find(n.options.elemSelHours)}if(!n.options.elemSelDays){n.prepend('<div class="ds-element ds-element-days"> <div class="ds-element-title">'+n.options.titleDays+'</div> <div class="ds-element-value ds-days">00</div> </div>');n.data.elemDays=n.find(".ds-days")}else{n.data.elemDays=n.find(n.options.elemSelDays)}n.addClass("dsCountDown");n.addClass("ds-"+n.options.theme);if(n.options.startDate&&n.options.endDate){n.data.interval=n.options.endDate.getTime()-n.options.startDate.getTime();if(n.data.interval>0){var e=n.data.interval/1e3;var t=e%86400;var r=t%3600;n.data.left=e;n.data.days=Math.floor(e/86400);n.data.hours=Math.floor(t/3600);n.data.minutes=Math.floor(r/60);n.data.seconds=Math.floor(r%60)}}n.start()};n.stop=function(e){if(n.data.running){clearInterval(n.data.thread);n.data.running=false}if(e){e(n)}};n.start=function(){e("#logger").append("<br/>Start");if(!n.data.running){e("#logger").append("<br/>Clock");if(n.data.left>0){if(n.options.onBevoreStart){n.options.onBevoreStart(n)}n.data.thread=setInterval(function(){if(n.data.left>0){n.data.left-=n.data.decreament;n.data.seconds-=n.data.decreament;if(n.data.seconds<=0&&(n.data.minutes>0||n.data.hours>0||n.data.days>0)){n.data.minutes--;n.data.seconds=60}if(n.data.minutes<=0&&(n.data.hours>0||n.data.days>0)){n.data.hours--;n.data.minutes=60}if(n.data.hours<=0&&n.data.days>0){n.data.days--;n.data.hours=24}if(n.data.elemDays)n.data.elemDays.html(n.data.days<10?"0"+n.data.days:n.data.days);if(n.data.elemHours)n.data.elemHours.html(n.data.hours<10?"0"+n.data.hours:n.data.hours);if(n.data.elemMinutes)n.data.elemMinutes.html(n.data.minutes<10?"0"+n.data.minutes:n.data.minutes);if(n.data.elemSeconds)n.data.elemSeconds.html(n.data.seconds<10?"0"+n.data.seconds:n.data.seconds);if(n.options.onClocking){n.options.onClocking(n)}}else{n.stop(n.options.onFinish)}},n.data.refreshed);n.data.running=true}else{if(n.options.onFinish){n.options.onFinish(n)}}}};n.init()}})(jQuery)