(function(factory){"use strict";typeof define=="function"&&define.amd?define(["jquery"],factory):factory(jQuery)})(function($){"use strict";var instances=[],matchers=[],defaultOptions={precision:100,elapse:!1,defer:!1};matchers.push(/^[0-9]*$/.source),matchers.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),matchers.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),matchers=new RegExp(matchers.join("|"));function parseDateString(dateString){if(dateString instanceof Date)return dateString;if(String(dateString).match(matchers))return String(dateString).match(/^[0-9]*$/)&&(dateString=Number(dateString)),String(dateString).match(/\-/)&&(dateString=String(dateString).replace(/\-/g,"/")),new Date(dateString);throw new Error("Couldn't cast `"+dateString+"` to a date object.")}var DIRECTIVE_KEY_MAP={Y:"years",m:"months",n:"daysToMonth",d:"daysToWeek",w:"weeks",W:"weeksToMonth",H:"hours",M:"minutes",S:"seconds",D:"totalDays",I:"totalHours",N:"totalMinutes",T:"totalSeconds"};function escapedRegExp(str){var sanitize=str.toString().replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1");return new RegExp(sanitize)}function strftime(offsetObject){return function(format){var directives=format.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);if(directives)for(var i=0,len=directives.length;i1?plural:singular}var Countdown=function(el,finalDate,options){this.el=el,this.$el=$(el),this.interval=null,this.offset={},this.options=$.extend({},defaultOptions),this.firstTick=!0,this.instanceNumber=instances.length,instances.push(this),this.$el.data("countdown-instance",this.instanceNumber),options&&(typeof options=="function"?(this.$el.on("update.countdown",options),this.$el.on("stoped.countdown",options),this.$el.on("finish.countdown",options)):this.options=$.extend({},defaultOptions,options)),this.setFinalDate(finalDate),this.options.defer===!1&&this.start()};$.extend(Countdown.prototype,{start:function(){this.interval!==null&&clearInterval(this.interval);var self=this;this.update(),this.interval=setInterval(function(){self.update.call(self)},this.options.precision)},stop:function(){clearInterval(this.interval),this.interval=null,this.dispatchEvent("stoped")},toggle:function(){this.interval?this.stop():this.start()},pause:function(){this.stop()},resume:function(){this.start()},remove:function(){this.stop.call(this),instances[this.instanceNumber]=null,delete this.$el.data().countdownInstance},setFinalDate:function(value){this.finalDate=parseDateString(value)},update:function(){if(this.$el.closest("html").length===0){this.remove();return}var now=new Date,newTotalSecsLeft;if(newTotalSecsLeft=this.finalDate.getTime()-now.getTime(),newTotalSecsLeft=Math.ceil(newTotalSecsLeft/1e3),newTotalSecsLeft=!this.options.elapse&&newTotalSecsLeft<0?0:Math.abs(newTotalSecsLeft),this.totalSecsLeft===newTotalSecsLeft||this.firstTick){this.firstTick=!1;return}else this.totalSecsLeft=newTotalSecsLeft;this.elapsed=now>=this.finalDate,this.offset={seconds:this.totalSecsLeft%60,minutes:Math.floor(this.totalSecsLeft/60)%60,hours:Math.floor(this.totalSecsLeft/60/60)%24,days:Math.floor(this.totalSecsLeft/60/60/24)%7,daysToWeek:Math.floor(this.totalSecsLeft/60/60/24)%7,daysToMonth:Math.floor(this.totalSecsLeft/60/60/24%30.4368),weeks:Math.floor(this.totalSecsLeft/60/60/24/7),weeksToMonth:Math.floor(this.totalSecsLeft/60/60/24/7)%4,months:Math.floor(this.totalSecsLeft/60/60/24/30.4368),years:Math.abs(this.finalDate.getFullYear()-now.getFullYear()),totalDays:Math.floor(this.totalSecsLeft/60/60/24),totalHours:Math.floor(this.totalSecsLeft/60/60),totalMinutes:Math.floor(this.totalSecsLeft/60),totalSeconds:this.totalSecsLeft},!this.options.elapse&&this.totalSecsLeft===0?(this.stop(),this.dispatchEvent("finish")):this.dispatchEvent("update")},dispatchEvent:function(eventName){var event=$.Event(eventName+".countdown");event.finalDate=this.finalDate,event.elapsed=this.elapsed,event.offset=$.extend({},this.offset),event.strftime=strftime(this.offset),this.$el.trigger(event)}}),$.fn.countdown=function(){var argumentsArray=Array.prototype.slice.call(arguments,0);return this.each(function(){var instanceNumber=$(this).data("countdown-instance");if(instanceNumber!==void 0){var instance=instances[instanceNumber],method=argumentsArray[0];Countdown.prototype.hasOwnProperty(method)?instance[method].apply(instance,argumentsArray.slice(1)):String(method).match(/^[$A-Z_][0-9A-Z_$]*$/i)===null?(instance.setFinalDate.call(instance,method),instance.start()):$.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi,method))}else new Countdown(this,argumentsArray[0],argumentsArray[1])})}}); //# sourceMappingURL=/cdn/shop/t/129/assets/countdown.js.map?v=9850902083478055731719875018