diff --git a/jquery.timeago.js b/jquery.timeago.js index cecfaeb8..b90caf62 100644 --- a/jquery.timeago.js +++ b/jquery.timeago.js @@ -42,6 +42,7 @@ allowFuture: false, localeTitle: false, cutoff: 0, + cutoffMessage: false, strings: { prefixAgo: null, prefixFromNow: null, @@ -170,6 +171,9 @@ if ( $s.cutoff == 0 || distance(data.datetime) < $s.cutoff) { $(this).text(inWords(data.datetime)); } + else if ($s.cutoffMessage && distance(data.datetime) >= $s.cutoff) { + $(this).text($s.cutoffMessage.concat(" ", inWords(new Date(new Date().getTime() - $s.cutoff)))); + } } return this; } diff --git a/test/index.html b/test/index.html index 225f5be7..1e17173d 100644 --- a/test/index.html +++ b/test/index.html @@ -66,6 +66,8 @@

Other formats

Cutoff

Date that is older than cutoff: (this should be displayed)

+ +

Date that is older than cutoff with message: (you shouldn't see this)

Date that is newer than cutoff: (you shouldn't see this)

@@ -228,8 +230,12 @@

Disposal

loadCutoffSetting(); $("abbr.cutoff").timeago(); + loadCutoffMessageSetting(); + $("abbr.cutoff.withCutoffMessage").timeago(); + unloadCutoffMessageSetting(); unloadCutoffSetting(); + var tooltip = $("#testTooltip").data("timeago"); $("abbr.todate").each(function () { @@ -316,6 +322,12 @@

Disposal

}), "Cutoff setting working fine"); }); + test("should give cutoff message for dates older than cutoff setting", function() { + ok(testElements("abbr.doCutoffWithCutoffMessage", function (element) { + return (element.html() === "over 7 days ago"); + }), "Cutoff message setting working fine"); + }); + test("should change dates newer than cutoff setting", function () { ok(testElements("abbr.dontCutoff", function (element) { return (element.html() === "less than a minute ago"); diff --git a/test/test_helpers.js b/test/test_helpers.js index 501de1bc..483d024a 100644 --- a/test/test_helpers.js +++ b/test/test_helpers.js @@ -30,6 +30,14 @@ function unloadCutoffSetting() { jQuery.timeago.settings.cutoff = 0; } +function loadCutoffMessageSetting() { + jQuery.timeago.settings.cutoffMessage = "over"; +} + +function unloadCutoffMessageSetting() { + jQuery.timeago.settings.cutoffMessage = false; +} + function setupDisposal() { jQuery.timeago.settings.refreshMillis = 50; $('abbr.disposal').attr("title", iso8601(new Date())).timeago();