1!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.Countdown=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 2var defaultOptions = { 3 date: "June 7, 2087 15:03:25", 4 refresh: 1000, 5 offset: 0, 6 onEnd: function() { 7 return; 8 }, 9 render: function (date) { 10 this.el.innerHTML = date.years + " years, " + 11 date.days + " days, " + 12 this.leadingZeros(date.hours) + " hours, " + 13 this.leadingZeros(date.min) + " min and " + 14 this.leadingZeros(date.sec) + " sec"; 15 } 16}; 17 18/** 19 * Countdown constructor 20 * @param {HTMLElement} el DOM node of the countdown 21 * @param {Object} options (optional) Options for the plugin 22 */ 23var Countdown = function(el, options) { 24 25 /** 26 * Reference to the DOM element 27 * @type {HTMLElement} 28 */ 29 this.el = el; 30 31 /** 32 * Options of the countdown plugin 33 * @type {Object} 34 */ 35 this.options = {}; 36 37 /** 38 * Interval reference or false if counter is stopped 39 * @type {Mixed} 40 */ 41 this.interval = false; 42 43 // merge default options and options into this.options 44 for (var i in defaultOptions) { 45 if (defaultOptions.hasOwnProperty(i)) { 46 this.options[i] = typeof options[i] !== 'undefined' ? options[i] : defaultOptions[i]; 47 48 if (i === 'date' && typeof this.options.date !== 'object') { 49 this.options.date = new Date(this.options.date); 50 } 51 52 // bind context for functions 53 if (typeof this.options[i] === 'function') { 54 this.options[i] = this.options[i].bind(this); 55 } 56 } 57 } 58 59 /** 60 * Get the difference between now and the end date 61 * @return {Object} Object with the diff information (years, days, hours, min, sec, millisec) 62 */ 63 this.getDiffDate = function() { 64 var diff = (this.options.date.getTime() - Date.now() + this.options.offset) / 1000; 65 66 var dateData = { 67 years: 0, 68 days: 0, 69 hours: 0, 70 min: 0, 71 sec: 0, 72 millisec: 0 73 }; 74 75 if (diff <= 0) { 76 if (this.interval) { 77 this.stop(); 78 this.options.onEnd(); 79 } 80 return dateData; 81 } 82 83 if (diff >= (365.25 * 86400)) { 84 dateData.years = Math.floor(diff / (365.25 * 86400)); 85 diff -= dateData.years * 365.25 * 86400; 86 } 87 88 if (diff >= 86400) { 89 dateData.days = Math.floor(diff / 86400); 90 diff -= dateData.days * 86400; 91 } 92 93 if (diff >= 3600) { 94 dateData.hours = Math.floor(diff / 3600); 95 diff -= dateData.hours * 3600; 96 } 97 98 if (diff >= 60) { 99 dateData.min = Math.floor(diff / 60); 100 diff -= dateData.min * 60; 101 } 102 103 dateData.sec = Math.round(diff); 104 105 dateData.millisec = diff % 1 * 1000; 106 107 return dateData; 108 }.bind(this); 109 110 /** 111 * Add leading zeros to a number 112 * @param {Number} num Input number 113 * @param {Number} length Length of the desired output 114 * @return {String} String of the desired length with leading zeros 115 */ 116 this.leadingZeros = function(num, length) { 117 length = length || 2; 118 num = String(num); 119 if (num.length > length) { 120 return num; 121 } 122 return (Array(length + 1).join('0') + num).substr(-length); 123 }; 124 125 /** 126 * Update the end date of the countdown 127 * @param {Mixed} newDate Date object or a String/Number that can be passed to the Date constructor 128 * @return {Countdown} Countdown instance 129 */ 130 this.update = function(newDate) { 131 if (typeof newDate !== 'object') { 132 newDate = new Date(newDate); 133 } 134 this.options.date = newDate; 135 this.render(); 136 return this; 137 }.bind(this); 138 139 /** 140 * Stop the countdown refresh / rerender 141 * @return {Countdown} Countdown instance 142 */ 143 this.stop = function() { 144 if (this.interval) { 145 clearInterval(this.interval); 146 this.interval = false; 147 } 148 return this; 149 }.bind(this); 150 151 /** 152 * Render the countdown 153 * @return {Countdown} Countdown instance 154 */ 155 this.render = function() { 156 this.options.render(this.getDiffDate()); 157 return this; 158 }.bind(this); 159 160 /** 161 * Start the countdown 162 * @return {Countdown} Countdown instance 163 */ 164 this.start = function() { 165 // don't start if the countdown is already started 166 if (this.interval) { return; } 167 168 this.render(); 169 170 if (this.options.refresh) { 171 this.interval = setInterval(this.render, this.options.refresh); 172 } 173 174 return this; 175 }.bind(this); 176 177 /** 178 * Update the offset 179 * @param {Number} offset New offset in ms 180 * @return {Countdown} Countdown instance 181 */ 182 this.updateOffset = function(offset) { 183 this.options.offset = offset; 184 return this; 185 }.bind(this); 186 187 188 // initial start of the countdown or initial render 189 this.start(); 190}; 191 192module.exports = Countdown; 193 194},{}],2:[function(require,module,exports){ 195var Countdown = require('./countdown.js'); 196var NAME = 'countdown'; 197var DATA_ATTR = 'date'; 198 199jQuery.fn.countdown = function(options) { 200 return $.each(this, function(i, el) { 201 var $el = $(el); 202 if (!$el.data(NAME)) { 203 // allow setting the date via the data-date attribute 204 if ($el.data(DATA_ATTR)) { 205 options.date = $el.data(DATA_ATTR); 206 } 207 $el.data(NAME, new Countdown(el, options)); 208 } 209 }); 210}; 211 212module.exports = Countdown; 213 214},{"./countdown.js":1}]},{},[2])(2) 215});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.