vendor/assets/javascripts/jquery.timeago.js in rails-timeago-2.5.1 vs vendor/assets/javascripts/jquery.timeago.js in rails-timeago-2.6.0

- old
+ new

@@ -1,11 +1,11 @@ /** * Timeago is a jQuery plugin that makes it easy to support automatically * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). * * @name timeago - * @version 1.1.0 + * @version 1.3.0 * @requires jQuery v1.2.3+ * @author Ryan McGeary * @license MIT License - http://www.opensource.org/licenses/mit-license.php * * For usage and examples, visit: @@ -39,10 +39,11 @@ $.extend($.timeago, { settings: { refreshMillis: 60000, allowFuture: false, localeTitle: false, + cutoff: 0, lang: "en", strings: { "en": { prefixAgo: null, prefixFromNow: null, suffixAgo: "ago", @@ -126,16 +127,26 @@ init: function(){ var refresh_el = $.proxy(refresh, this); refresh_el(); var $s = $t.settings; if ($s.refreshMillis > 0) { - setInterval(refresh_el, $s.refreshMillis); + this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis); } }, update: function(time){ $(this).data('timeago', { datetime: $t.parse(time) }); refresh.apply(this); + }, + updateFromDOM: function(){ + $(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) }); + refresh.apply(this); + }, + dispose: function () { + if (this._timeagoInterval) { + window.clearInterval(this._timeagoInterval); + this._timeagoInterval = null; + } } }; $.fn.timeago = function(action, options) { var fn = action ? functions[action] : functions.init; @@ -149,11 +160,15 @@ return this; }; function refresh() { var data = prepareData(this); + var $s = $t.settings; + if (!isNaN(data.datetime)) { - $(this).text(inWords(data.datetime, ($(this).attr('lang')) ? $(this).attr('lang') : $t.settings.lang)); + if ( $s.cutoff == 0 || distance(data.datetime) < $s.cutoff) { + $(this).text(inWords(data.datetime, ($(this).attr('lang')) ? $(this).attr('lang') : $t.settings.lang)); + } } return this; } function prepareData(element) {