|
发表于 2018-1-2 16:51:00
|
显示全部楼层
[ol][*]/*
[*] * jQuery Countdown - v1.2.4
[*] * http://github.com/kemar/jquery.countdown
[*] * Licensed MIT
[*] */
[*](function($,g,i,j){"use strict";var k='countDown';var l={css_class:'countdown',only_show_days:false,always_show_days:false,with_labels:true,with_seconds:true,with_separators:true,label_dd:'days',label_hh:'hours',label_mm:'minutes',label_ss:'seconds',separator:':',separator_days:',',timeElement:''};function CountDown(a,b){this.element=$(a);this.options=$.extend({},l,b);this._defaults=l;this._name=k;this.init()}$.extend(CountDown.prototype,{init:function(){if(this.element.children().length){return}if(this.element.attr('datetime')){this.endDate=this.parseEndDate(this.element.attr('datetime'))}if(this.endDate===j){this.endDate=this.parseEndDate(this.element.text())}if(this.endDate===j){return}if(this.element.is('time')){this.timeElement=this.element}else{this.timeElement=$(this.options.timeElement);this.element.html(this.timeElement)}this.markup();this.setTimeoutDelay=this.sToMs(1);this.daysVisible=true;this.timeElement.bind('time.elapsed',this.options.onTimeElapsed);this.doCountDown()},parseEndDate:function(a){var d;d=this.parseDuration(a);if(d instanceof Date){return d}d=this.parseDateTime(a);if(d instanceof Date){return d}d=this.parseHumanReadableDuration(a);if(d instanceof Date){return d}d=Date.parse(a);if(!isNaN(d)){return new Date(d)}},parseDuration:function(a){var b=a.match(/^P(?:(\d+)D)?T?(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)(?:\.(\d{1,3}))?S)?$/);if(b){var d,dd,hh,mm,ss,ms;dd=b[1]?this.dToMs(b[1]):0;hh=b[2]?this.hToMs(b[2]):0;mm=b[3]?this.mToMs(b[3]):0;ss=b[4]?this.sToMs(b[4]):0;ms=b[5]?parseInt(b[5],10):0;d=new Date();d.setTime(d.getTime()+dd+hh+mm+ss+ms);return d}},parseDateTime:function(a){var b=a.match(/^(\d{4,})-(\d{2})-(\d{2})[T\s](\d{2}):(\d{2})(?:\:(\d{2}))?(?:\.(\d{1,3}))?([Z\+\-\:\d]+)?$/);if(b){var c=b[8]?b[8].match(/^([\+\-])?(\d{2}):?(\d{2})$/):j;var e=0;if(c){e=this.hToMs(c[2])+this.mToMs(c[3]);e=(c[1]==='-')?e:-e}var d,yy,mo,dd,hh,mm,ss,ms;yy=b[1];mo=b[2]-1;dd=b[3];hh=b[4]||0;mm=b[5]||0;ss=b[6]||0;ms=b[7]||0;d=new Date(Date.UTC(yy,mo,dd,hh,mm,ss,ms));d.setTime(d.getTime()+e);return d}},parseHumanReadableDuration:function(a){var b=a.match(/^(?:(\d+).+\s)?(\d+)[h:]\s?(\d+)[m:]?\s?(\d+)?[s]?(?:\.(\d{1,3}))?$/);if(b){var d,dd,hh,mm,ss,ms;d=new Date();dd=b[1]?this.dToMs(b[1]):0;hh=b[2]?this.hToMs(b[2]):0;mm=b[3]?this.mToMs(b[3]):0;ss=b[4]?this.sToMs(b[4]):0;ms=b[5]?parseInt(b[5],10):0;d.setTime(d.getTime()+dd+hh+mm+ss+ms);return d}},sToMs:function(s){return parseInt(s,10)*1000},mToMs:function(m){return parseInt(m,10)*60*1000},hToMs:function(h){return parseInt(h,10)*60*60*1000},dToMs:function(d){return parseInt(d,10)*24*60*60*1000},msToS:function(a){return parseInt((a/1000)%60,10)},msToM:function(a){return parseInt((a/1000/60)%60,10)},msToH:function(a){return parseInt((a/1000/60/60)%24,10)},msToD:function(a){return parseInt((a/1000/60/60/24),10)},markup:function(){var a=['','','',this.options.label_dd,'','','',this.options.separator_days,'','','','','',this.options.label_hh,'','','',this.options.separator,'','','','','',this.options.label_mm,'','','',this.options.separator,'','','','','',this.options.label_ss,'',''];this.timeElement.html(a.join(''));if(!this.options.with_labels){this.timeElement.find('.label').remove()}if(!this.options.with_separators){this.timeElement.find('.separator').remove()}if(!this.options.with_seconds){this.timeElement.find('.item-ss').remove();this.timeElement.find('.separator').last().remove()}this.item_dd=this.timeElement.find('.item-dd');this.separator_dd=this.timeElement.find('.separator-dd');this.remaining_dd=this.timeElement.find('.dd');this.remaining_hh1=this.timeElement.find('.hh-1');this.remaining_hh2=this.timeElement.find('.hh-2');this.remaining_mm1=this.timeElement.find('.mm-1');this.remaining_mm2=this.timeElement.find('.mm-2');this.remaining_ss1=this.timeElement.find('.ss-1');this.remaining_ss2=this.timeElement.find('.ss-2');this.timeElement.addClass(this.options.css_class)},doCountDown:function(){var a=this.endDate.getTime()-new Date().getTime();var b=this.msToS(a);var c=this.msToM(a);var d=this.msToH(a);var e=this.msToD(a);if(a复制代码 |
|