Permalink
Browse files

Update to jQuery timeago 1.5.3

  • Loading branch information...
1 parent 759009c commit 4a2350736a159f16a0ca105d76317a5fb17d5f25 @koraktor committed Jan 2, 2017
Showing with 28 additions and 13 deletions.
  1. +28 −13 vendor/assets/javascripts/jquery.timeago.js
@@ -3,21 +3,23 @@
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
*
* @name timeago
- * @version 1.4.1
+ * @version 1.5.3
* @requires jQuery v1.2.3+
* @author Ryan McGeary
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
*
* For usage and examples, visit:
* http://timeago.yarp.com/
*
- * Copyright (c) 2008-2013, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
+ * Copyright (c) 2008-2015, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
+ } else if (typeof module === 'object' && typeof module.exports === 'object') {
+ factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
@@ -43,6 +45,7 @@
allowFuture: false,
localeTitle: false,
cutoff: 0,
+ autoDispose: true,
strings: {
prefixAgo: null,
prefixFromNow: null,
@@ -66,7 +69,7 @@
},
inWords: function(distanceMillis) {
- if(!this.settings.allowPast && ! this.settings.allowFuture) {
+ if (!this.settings.allowPast && ! this.settings.allowFuture) {
throw 'timeago allowPast and allowFuture settings can not both be set to false.';
}
@@ -80,7 +83,7 @@
}
}
- if(!this.settings.allowPast && distanceMillis >= 0) {
+ if (!this.settings.allowPast && distanceMillis >= 0) {
return this.settings.strings.inPast;
}
@@ -136,21 +139,21 @@
// init is default when no action is given
// functions are called with context of a single element
var functions = {
- init: function(){
+ init: function() {
var refresh_el = $.proxy(refresh, this);
refresh_el();
var $s = $t.settings;
if ($s.refreshMillis > 0) {
this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
}
},
- update: function(time){
- var parsedTime = $t.parse(time);
- $(this).data('timeago', { datetime: parsedTime });
- if($t.settings.localeTitle) $(this).attr("title", parsedTime.toLocaleString());
+ update: function(timestamp) {
+ var date = (timestamp instanceof Date) ? timestamp : $t.parse(timestamp);
+ $(this).data('timeago', { datetime: date });
+ if ($t.settings.localeTitle) $(this).attr("title", date.toLocaleString());
refresh.apply(this);
},
- updateFromDOM: function(){
+ updateFromDOM: function() {
$(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
refresh.apply(this);
},
@@ -164,23 +167,35 @@
$.fn.timeago = function(action, options) {
var fn = action ? functions[action] : functions.init;
- if(!fn){
+ if (!fn) {
throw new Error("Unknown function name '"+ action +"' for timeago");
}
// each over objects here and call the requested function
- this.each(function(){
+ this.each(function() {
fn.call(this, options);
});
return this;
};
function refresh() {
- var data = prepareData(this);
var $s = $t.settings;
+ //check if it's still visible
+ if ($s.autoDispose && !$.contains(document.documentElement,this)) {
+ //stop if it has been removed
+ $(this).timeago("dispose");
+ return this;
+ }
+
+ var data = prepareData(this);
+
if (!isNaN(data.datetime)) {
if ( $s.cutoff == 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
$(this).text(inWords(data.datetime));
+ } else {
+ if ($(this).attr('title').length > 0) {
+ $(this).text($(this).attr('title'));
+ }
}
}
return this;

0 comments on commit 4a23507

Please sign in to comment.