|
|
@ -3,7 +3,7 @@
|
|
|
|
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
|
|
|
|
* updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @name timeago
|
|
|
|
* @name timeago
|
|
|
|
* @version 1.4.1
|
|
|
|
* @version 1.5.3
|
|
|
|
* @requires jQuery v1.2.3+
|
|
|
|
* @requires jQuery v1.2.3+
|
|
|
|
* @author Ryan McGeary
|
|
|
|
* @author Ryan McGeary
|
|
|
|
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
|
|
|
|
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
|
|
|
@ -18,6 +18,8 @@
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define(['jquery'], factory);
|
|
|
|
define(['jquery'], factory);
|
|
|
|
|
|
|
|
} else if (typeof module === 'object' && typeof module.exports === 'object') {
|
|
|
|
|
|
|
|
factory(require('jquery'));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Browser globals
|
|
|
|
// Browser globals
|
|
|
|
factory(jQuery);
|
|
|
|
factory(jQuery);
|
|
|
@ -43,6 +45,7 @@
|
|
|
|
allowFuture: false,
|
|
|
|
allowFuture: false,
|
|
|
|
localeTitle: false,
|
|
|
|
localeTitle: false,
|
|
|
|
cutoff: 0,
|
|
|
|
cutoff: 0,
|
|
|
|
|
|
|
|
autoDispose: true,
|
|
|
|
strings: {
|
|
|
|
strings: {
|
|
|
|
prefixAgo: null,
|
|
|
|
prefixAgo: null,
|
|
|
|
prefixFromNow: null,
|
|
|
|
prefixFromNow: null,
|
|
|
@ -144,10 +147,10 @@
|
|
|
|
this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
|
|
|
|
this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
update: function(time){
|
|
|
|
update: function(timestamp) {
|
|
|
|
var parsedTime = $t.parse(time);
|
|
|
|
var date = (timestamp instanceof Date) ? timestamp : $t.parse(timestamp);
|
|
|
|
$(this).data('timeago', { datetime: parsedTime });
|
|
|
|
$(this).data('timeago', { datetime: date });
|
|
|
|
if($t.settings.localeTitle) $(this).attr("title", parsedTime.toLocaleString());
|
|
|
|
if ($t.settings.localeTitle) $(this).attr("title", date.toLocaleString());
|
|
|
|
refresh.apply(this);
|
|
|
|
refresh.apply(this);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
updateFromDOM: function() {
|
|
|
|
updateFromDOM: function() {
|
|
|
@ -175,19 +178,24 @@
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function refresh() {
|
|
|
|
function refresh() {
|
|
|
|
|
|
|
|
var $s = $t.settings;
|
|
|
|
|
|
|
|
|
|
|
|
//check if it's still visible
|
|
|
|
//check if it's still visible
|
|
|
|
if(!$.contains(document.documentElement,this)){
|
|
|
|
if ($s.autoDispose && !$.contains(document.documentElement,this)) {
|
|
|
|
//stop if it has been removed
|
|
|
|
//stop if it has been removed
|
|
|
|
$(this).timeago("dispose");
|
|
|
|
$(this).timeago("dispose");
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var data = prepareData(this);
|
|
|
|
var data = prepareData(this);
|
|
|
|
var $s = $t.settings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isNaN(data.datetime)) {
|
|
|
|
if (!isNaN(data.datetime)) {
|
|
|
|
if ( $s.cutoff == 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
|
|
|
|
if ( $s.cutoff == 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
|
|
|
|
$(this).text(inWords(data.datetime));
|
|
|
|
$(this).text(inWords(data.datetime));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ($(this).attr('title').length > 0) {
|
|
|
|
|
|
|
|
$(this).text($(this).attr('title'));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|