Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions jquery.timeago.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && typeof module.exports === 'object') {
} if (typeof module === 'object' && typeof module.exports === 'object') {
factory(require('jquery'));
} else {
// Browser globals
Expand All @@ -42,8 +42,11 @@
settings: {
refreshMillis: 60000,
allowPast: true,
allowFuture: false,
allowFuture: true,
localeTitle: false,
allowColors: true,
inPast: true,
inPastColor: { past: 'timeago-past', future: 'timeago-future' },
cutoff: 0,
strings: {
prefixAgo: null,
Expand All @@ -67,6 +70,8 @@
}
},



inWords: function(distanceMillis) {
if(!this.settings.allowPast && ! this.settings.allowFuture) {
throw 'timeago allowPast and allowFuture settings can not both be set to false.';
Expand All @@ -75,13 +80,18 @@
var $l = this.settings.strings;
var prefix = $l.prefixAgo;
var suffix = $l.suffixAgo;
inPast = true;

if (this.settings.allowFuture) {
if (distanceMillis < 0) {
prefix = $l.prefixFromNow;
suffix = $l.suffixFromNow;
inPast = false;
}
}

this.settings.inPast = inPast;

if(!this.settings.allowPast && distanceMillis >= 0) {
return this.settings.strings.inPast;
}
Expand All @@ -98,6 +108,7 @@
return string.replace(/%d/i, value);
}


var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
seconds < 90 && substitute($l.minute, 1) ||
minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
Expand Down Expand Up @@ -141,6 +152,7 @@
init: function(){
var refresh_el = $.proxy(refresh, this);
refresh_el();
refresh.apply(this);
var $s = $t.settings;
if ($s.refreshMillis > 0) {
this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
Expand Down Expand Up @@ -176,6 +188,15 @@
return this;
};

function getTime(set, tense) {
if(!set) {
return $.timeago.settings.inPast;

} else {
$.timeago.settings.inPast = tense;
}
};

function refresh() {
//check if it's still visible
if(!$.contains(document.documentElement,this)){
Expand Down Expand Up @@ -206,6 +227,16 @@
element.attr("title", text);
}
}
if($t.settings.allowColors) {
var colorClass;
if($t.settings.inPast) {
colorClass = $t.settings.inPastColor.past;
} else {
colorClass = $t.settings.inPastColor.future;
}
element.addClass(colorClass);
}

return element.data("timeago");
}

Expand Down