vendor: 5,481 bytes, lines 1-170
1/** 2 * Timeago is a jQuery plugin that makes it easy to support automatically 3 * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). 4 * 5 * @name timeago 6 * @version 1.2.0 7 * @requires jQuery v1.2.3+ 8 * @author Ryan McGeary 9 * @license MIT License - http://www.opensource.org/licenses/mit-license.php 10 * 11 * For usage and examples, visit: 12 * http://timeago.yarp.com/ 13 * 14 * Copyright (c) 2008-2013, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org) 15 */ 16 17(function (factory) { 18 if (typeof define === 'function' && define.amd) { 19 // AMD. Register as an anonymous module. 20 define(['jquery'], factory); 21 } else { 22 // Browser globals 23 factory(jQuery); 24 } 25}(function ($) { 26 $.timeago = function(timestamp) { 27 if (timestamp instanceof Date) { 28 return inWords(timestamp); 29 } else if (typeof timestamp === "string") { 30 return inWords($.timeago.parse(timestamp)); 31 } else if (typeof timestamp === "number") { 32 return inWords(new Date(timestamp)); 33 } else { 34 return inWords($.timeago.datetime(timestamp)); 35 } 36 }; 37 var $t = $.timeago; 38 39 $.extend($.timeago, { 40 settings: { 41 refreshMillis: 60000, 42 allowFuture: false, 43 localeTitle: false, 44 cutoff: 0, 45 strings: { 46 prefixAgo: null, 47 prefixFromNow: null, 48 suffixAgo: "ago", 49 suffixFromNow: "from now", 50 seconds: "less than a minute", 51 minute: "about a minute", 52 minutes: "%d minutes", 53 hour: "about an hour", 54 hours: "about %d hours", 55 day: "a day", 56 days: "%d days", 57 month: "about a month", 58 months: "%d months", 59 year: "about a year", 60 years: "%d years", 61 wordSeparator: " ", 62 numbers: [] 63 } 64 }, 65 inWords: function(distanceMillis) { 66 var $l = this.settings.strings; 67 var prefix = $l.prefixAgo; 68 var suffix = $l.suffixAgo; 69 if (this.settings.allowFuture) { 70 if (distanceMillis < 0) { 71 prefix = $l.prefixFromNow; 72 suffix = $l.suffixFromNow; 73 } 74 } 75 76 var seconds = Math.abs(distanceMillis) / 1000; 77 var minutes = seconds / 60; 78 var hours = minutes / 60; 79 var days = hours / 24; 80 var years = days / 365; 81 82 function substitute(stringOrFunction, number) { 83 var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction; 84 var value = ($l.numbers && $l.numbers[number]) || number; 85 return string.replace(/%d/i, value); 86 } 87 88 var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) || 89 seconds < 90 && substitute($l.minute, 1) || 90 minutes < 45 && substitute($l.minutes, Math.round(minutes)) || 91 minutes < 90 && substitute($l.hour, 1) || 92 hours < 24 && substitute($l.hours, Math.round(hours)) || 93 hours < 42 && substitute($l.day, 1) || 94 days < 30 && substitute($l.days, Math.round(days)) || 95 days < 45 && substitute($l.month, 1) || 96 days < 365 && substitute($l.months, Math.round(days / 30)) || 97 years < 1.5 && substitute($l.year, 1) || 98 substitute($l.years, Math.round(years)); 99 100 var separator = $l.wordSeparator || ""; 101 if ($l.wordSeparator === undefined) { separator = " "; } 102 return $.trim([prefix, words, suffix].join(separator)); 103 }, 104 parse: function(iso8601) { 105 var s = $.trim(iso8601); 106 s = s.replace(/\.\d+/,""); // remove milliseconds 107 s = s.replace(/-/,"/").replace(/-/,"/"); 108 s = s.replace(/T/," ").replace(/Z/," UTC"); 109 s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400 110 return new Date(s); 111 }, 112 datetime: function(elem) { 113 var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title"); 114 return $t.parse(iso8601); 115 }, 116 isTime: function(elem) { 117 // jQuery's `is()` doesn't play well with HTML5 in IE 118 return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time"); 119 } 120 }); 121 122 // functions that can be called via $(el).timeago('action') 123 // init is default when no action is given 124 // functions are called with context of a single element 125 var functions = { 126 init: function(){ 127 var refresh_el = $.proxy(refresh, this); 128 refresh_el(); 129 var $s = $t.settings; 130 if ($s.refreshMillis > 0) { 131 setInterval(refresh_el, $s.refreshMillis); 132 } 133 }, 134 update: function(time){ 135 $(this).data('timeago', { datetime: $t.parse(time) }); 136 refresh.apply(this); 137 } 138 }; 139 140 $.fn.timeago = function(action, options) { 141 var fn = action ? functions[action] : functions.init; 142 if(!fn){ 143 throw new Error("Unknown function name '"+ action +"' for timeago"); 144 } 145 // each over objects here and call the requested function 146 this.each(function(){ 147 fn.call(this, options); 148 }); 149 return this; 150 }; 151 152 function refresh() { 153 var data = prepareData(this); 154 var $s = $t.settings; 155 156 if (!isNaN(data.datetime)) { 157 if ( $s.cutoff == 0 || distance(data.datetime) < $s.cutoff) { 158 $(this).text(inWords(data.datetime)); 159 } 160 } 161 return this; 162 } 163 164 function prepareData(element) { 165 element = $(element); 166 if (!element.data("timeago")) { 167 element.data("timeago", { datetime: $t.datetime(element) }); 168 var text = $.trim(element.text()); 169 if ($t.settings.localeTitle) { 170 element.attr("title", element.data('timeago').datetime.toLocaleStr
170ing()); 171 } else if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) { 172 element.attr("title", text); 173 } 174 } 175 return element.data("timeago"); 176 } 177 178 function inWords(date) { 179 return $t.inWords(distance(date)); 180 } 181 182 function distance(date) { 183 return (new Date().getTime() - date.getTime()); 184 } 185 186 // fix for IE6 suckage 187 document.createElement("abbr"); 188 document.createElement("time"); 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.