1// Copyright 2012, Terry Tai, Pragmatic.ly 2// https://pragmatic.ly/ 3// Licensed under the MIT license. 4// https://github.com/pragmaticly/smart-time-ago/blob/master/LICENSE 5// 6// Generated by CoffeeScript 1.3.3 7 8(function() { 9 var TimeAgo; 10 11 TimeAgo = (function() { 12 13 function TimeAgo(element, options) { 14 this.startInterval = 60000; 15 this.init(element, options); 16 } 17 18 TimeAgo.prototype.init = function(element, options) { 19 this.$element = $(element); 20 this.options = $.extend({}, $.fn.timeago.defaults, options); 21 this.updateTime(); 22 return this.startTimer(); 23 }; 24 25 TimeAgo.prototype.startTimer = function() { 26 var self; 27 self = this; 28 return this.interval = setInterval((function() { 29 return self.refresh(); 30 }), this.startInterval); 31 }; 32 33 TimeAgo.prototype.stopTimer = function() { 34 return clearInterval(this.interval); 35 }; 36 37 TimeAgo.prototype.restartTimer = function() { 38 this.stopTimer(); 39 return this.startTimer(); 40 }; 41 42 TimeAgo.prototype.refresh = function() { 43 this.updateTime(); 44 return this.updateInterval(); 45 }; 46 47 TimeAgo.prototype.updateTime = function() { 48 var self; 49 self = this; 50 return this.$element.findAndSelf(this.options.selector).each(function() { 51 var timeAgoInWords; 52 timeAgoInWords = self.timeAgoInWords($(this).attr(self.options.attr)); 53 return $(this).html(timeAgoInWords); 54 }); 55 }; 56 57 TimeAgo.prototype.updateInterval = function() { 58 var filter, newestTime, newestTimeInMinutes, newestTimeSrc; 59 if (this.$element.findAndSelf(this.options.selector).length > 0) { 60 if (this.options.dir === "up") { 61 filter = ":first"; 62 } else if (this.options.dir === "down") { 63 filter = ":last"; 64 } 65 newestTimeSrc = this.$element.findAndSelf(this.options.selector).filter(filter).attr(this.options.attr); 66 newestTime = this.parse(newestTimeSrc); 67 newestTimeInMinutes = this.getTimeDistanceInMinutes(newestTime); 68 if (newestTimeInMinutes >= 0 && newestTimeInMinutes <= 44 && this.startInterval !== 60000) { 69 this.startInterval = 60000; 70 return this.restartTimer(); 71 } else if (newestTimeInMinutes >= 45 && newestTimeInMinutes <= 89 && this.startInterval !== 60000 * 22) { 72 this.startInterval = 60000 * 22; 73 return this.restartTimer(); 74 } else if (newestTimeInMinutes >= 90 && newestTimeInMinutes <= 2519 && this.startInterval !== 60000 * 30) { 75 this.startInterval = 60000 * 30; 76 return this.restartTimer(); 77 } else if (newestTimeInMinutes >= 2520 && this.startInterval !== 60000 * 60 * 12) { 78 this.startInterval = 60000 * 60 * 12; 79 return this.restartTimer(); 80 } 81 } 82 }; 83 84 TimeAgo.prototype.timeAgoInWords = function(timeString) { 85 var absolutTime; 86 absolutTime = this.parse(timeString); 87 return "" + this.options.lang.prefixes.ago + (this.distanceOfTimeInWords(absolutTime)) + this.options.lang.suffix; 88 }; 89 90 TimeAgo.prototype.parse = function(iso8601) { 91 var timeStr; 92 93 timeStr = $.trim(iso8601); 94 95 timeStr = timeStr.replace(/\.\d\d\d+/, ""); 96 timeStr = timeStr.replace(/-/, "/").replace(/-/, "/"); 97 timeStr = timeStr.replace(/T/, " ").replace(/Z/, " UTC"); 98 timeStr = timeStr.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2"); 99 100 return new Date(timeStr); 101 }; 102 103 TimeAgo.prototype.getTimeDistanceInMinutes = function(absolutTime) { 104 var timeDistance; 105 timeDistance = new Date().getTime() - absolutTime.getTime(); 106 return Math.round((Math.abs(timeDistance) / 1000) / 60); 107 }; 108 109 TimeAgo.prototype.distanceOfTimeInWords = function(absolutTime) { 110 var dim; 111 dim = this.getTimeDistanceInMinutes(absolutTime); 112 if (dim === 0) { 113 return "" + this.options.lang.prefixes.lt + ($().timeago.lang == 'fr' ? "e " : ' ') + this.options.lang.units.minute; 114 } else if (dim === 1) { 115 return "1 " + this.options.lang.units.minute; 116 } else if (dim >= 2 && dim <= 44) { 117 return "" + dim + " " + this.options.lang.units.minutes; 118 } else if (dim >= 45 && dim <= 89) { 119 return "" + this.options.lang.prefixes.about + " 1 " + this.options.lang.units.hour; 120 } else if (dim >= 90 && dim <= 1439) { 121 return "" + this.options.lang.prefixes.about + " " + (Math.round(dim / 60)) + " " + this.options.lang.units.hours; 122 } else if (dim >= 1440 && dim <= 2519) { 123 return "1 " + this.options.lang.units.day; 124 } else if (dim >= 2520 && dim <= 43199) { 125 return "" + (Math.round(dim / 1440)) + " " + this.options.lang.units.days; 126 } else if (dim >= 43200 && dim <= 86399) { 127 return "" + this.options.lang.prefixes.about + " 1 " + this.options.lang.units.month; 128 } else if (dim >= 86400 && dim <= 525599) { 129 return "" + (Math.round(dim / 43200)) + " " + this.options.lang.units.months; 130 } else if (dim >= 525600 && dim <= 655199) { 131 return "" + this.options.lang.prefixes.about + " 1 " + this.options.lang.units.year; 132 } else if (dim >= 655200 && dim <= 914399) { 133 return "" + this.options.lang.prefixes.over + " 1 " + this.options.lang.units.year; 134 } else if (dim >= 914400 && dim <= 1051199) { 135 return "" + this.options.lang.prefixes.almost + " 2 " + this.options.lang.units.years; 136 } else { 137 return "" + this.options.lang.prefixes.about + " " + (Math.round(dim / 525600)) + " " + this.options.lang.units.years; 138 } 139 }; 140 141 return TimeAgo; 142 143 })(); 144 145 $.fn.timeago = function(options) { 146 if (options == null) { 147 options = {}; 148 } 149 return this.each(function() { 150 var $this, data; 151 $this = $(this); 152 data = $this.data("timeago"); 153 if (!data) { 154 $this.data("timeago", new TimeAgo(this, options)); 155 } 156 if (typeof options === 'string') { 157 return data[options](); 158 } 159 }); 160 }; 161 162 $.fn.findAndSelf = function(selector) { 163 return this.find(selector).add(this.filter(selector)); 164 }; 165 166 $.fn.timeago.Constructor = TimeAgo; 167 168 $.fn.timeago.defaults = { 169 selector: 'time.timeago', 170 attr: 'datetime', 171 dir: 'up', 172 lang: { 173 units: { 174 second: "second", 175 seconds: "seconds", 176 minute: "minute", 177 minutes: "minutes", 178 hour: "hour", 179 hours: "hours", 180 day: "day", 181 days: "days", 182 month: "month", 183 months: "months", 184 year: "year", 185 years: "years" 186 }, 187 prefixes: { 188 lt: "less than a", 189 about: "about", 190 over: "over", 191 almost: "almost", 192 ago: "" 193 }, 194 suffix: ' ago' 195 } 196 }; 197 198}).call(this); 199 200$('span.timeAgo').timeago();
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.