vendor: 7,345 bytes, lines 1-189
1/*! 2 * The Final Countdown for jQuery v2.0.4 3 */ 4(function(factory) { 5 "use strict"; 6 if (typeof define === "function" && define.amd) { 7 define([ "jquery" ], factory); 8 } else { 9 factory(jQuery); 10 } 11})(function($) { 12 "use strict"; 13 var PRECISION = 100; 14 var instances = [], matchers = []; 15 matchers.push(/^[0-9]*$/.source); 16 matchers.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); 17 matchers.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source); 18 matchers = new RegExp(matchers.join("|")); 19 function parseDateString(dateString) { 20 if (dateString instanceof Date) { 21 return dateString; 22 } 23 if (String(dateString).match(matchers)) { 24 if (String(dateString).match(/^[0-9]*$/)) { 25 dateString = Number(dateString); 26 } 27 if (String(dateString).match(/\-/)) { 28 dateString = String(dateString).replace(/\-/g, "/"); 29 } 30 return new Date(dateString); 31 } else { 32 throw new Error("Couldn't cast `" + dateString + "` to a date object."); 33 } 34 } 35 var DIRECTIVE_KEY_MAP = { 36 Y: "years", 37 m: "months", 38 w: "weeks", 39 d: "days", 40 D: "totalDays", 41 H: "hours", 42 M: "minutes", 43 S: "seconds" 44 }; 45 function strftime(offsetObject) { 46 return function(format) { 47 var directives = format.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi); 48 if (directives) { 49 for (var i = 0, len = directives.length; i < len; ++i) { 50 var directive = directives[i].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/), regexp = new RegExp(directive[0]), modifier = directive[1] || "", plural = directive[3] || "", value = null; 51 directive = directive[2]; 52 if (DIRECTIVE_KEY_MAP.hasOwnProperty(directive)) { 53 value = DIRECTIVE_KEY_MAP[directive]; 54 value = Number(offsetObject[value]); 55 } 56 if (value !== null) { 57 if (modifier === "!") { 58 value = pluralize(plural, value); 59 } 60 if (modifier === "") { 61 if (value < 10) { 62 value = "0" + value.toString(); 63 } 64 } 65 format = format.replace(regexp, value.toString()); 66 } 67 } 68 } 69 format = format.replace(/%%/, "%"); 70 return format; 71 }; 72 } 73 function pluralize(format, count) { 74 var plural = "s", singular = ""; 75 if (format) { 76 format = format.replace(/(:|;|\s)/gi, "").split(/\,/); 77 if (format.length === 1) { 78 plural = format[0]; 79 } else { 80 singular = format[0]; 81 plural = format[1]; 82 } 83 } 84 if (Math.abs(count) === 1) { 85 return singular; 86 } else { 87 return plural; 88 } 89 } 90 var Countdown = function(el, finalDate, callback) { 91 this.el = el; 92 this.$el = $(el); 93 this.interval = null; 94 this.offset = {}; 95 this.instanceNumber = instances.length; 96 instances.push(this); 97 this.$el.data("countdown-instance", this.instanceNumber); 98 if (callback) { 99 this.$el.on("update.countdown", callback); 100 this.$el.on("stoped.countdown", callback); 101 this.$el.on("finish.countdown", callback); 102 } 103 this.setFinalDate(finalDate); 104 this.start(); 105 }; 106 $.extend(Countdown.prototype, { 107 start: function() { 108 if (this.interval !== null) { 109 clearInterval(this.interval); 110 } 111 var self = this; 112 this.update(); 113 this.interval = setInterval(function() { 114 self.update.call(self); 115 }, PRECISION); 116 }, 117 stop: function() { 118 clearInterval(this.interval); 119 this.interval = null; 120 this.dispatchEvent("stoped"); 121 }, 122 pause: function() { 123 this.stop.call(this); 124 }, 125 resume: function() { 126 this.start.call(this); 127 }, 128 remove: function() { 129 this.stop(); 130 instances[this.instanceNumber] = null; 131 delete this.$el.data().countdownInstance; 132 }, 133 setFinalDate: function(value) { 134 this.finalDate = parseDateString(value); 135 }, 136 update: function() { 137 if (this.$el.closest("html").length === 0) { 138 this.remove(); 139 return; 140 } 141 this.totalSecsLeft = this.finalDate.getTime() - new Date().getTime(); 142 this.totalSecsLeft = Math.ceil(this.totalSecsLeft / 1e3); 143 this.totalSecsLeft = this.totalSecsLeft < 0 ? 0 : this.totalSecsLeft; 144 this.offset = { 145 seconds: this.totalSecsLeft % 60, 146 minutes: Math.floor(this.totalSecsLeft / 60) % 60, 147 hours: Math.floor(this.totalSecsLeft / 60 / 60) % 24, 148 days: Math.floor(this.totalSecsLeft / 60 / 60 / 24) % 7, 149 totalDays: Math.floor(this.totalSecsLeft / 60 / 60 / 24), 150 weeks: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 7), 151 months: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 30), 152 years: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 365) 153 }; 154 if (this.totalSecsLeft === 0) { 155 this.stop(); 156 this.dispatchEvent("finish"); 157 } else { 158 this.dispatchEvent("update"); 159 } 160 }, 161 dispatchEvent: function(eventName) { 162 var event = $.Event(eventName + ".countdown"); 163 event.finalDate = this.finalDate; 164 event.offset = $.extend({}, this.offset); 165 event.strftime = strftime(this.offset); 166 this.$el.trigger(event); 167 } 168 }); 169 $.fn.countdown = function() { 170 var argumentsArray = Array.prototype.slice.call(arguments, 0); 171 return this.each(function() { 172 var instanceNumber = $(this).data("countdown-instance"); 173 if (instanceNumber !== undefined) { 174 var instance = instances[instanceNumber], method = argumentsArray[0]; 175 if (Countdown.prototype.hasOwnProperty(method)) { 176 instance[method].apply(instance, argumentsArray.slice(1)); 177 } else if (String(method).match(/^[$A-Z_][0-9A-Z_$]*$/i) === null) { 178 instance.setFinalDate.call(instance, method); 179 instance.start(); 180 } else { 181 $.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi, method)); 182 } 183 } else { 184 new Countdown(this, argumentsArray[0], argumentsArray[1]); 185 } 186 }); 187 }; 188}); 189
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.