mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2024-11-27 01:35:40 -05:00
Cutoff setting for leaving older dates alone.
The cutoff setting, if set to something other than 0, ensures that dates older than this number of milliseconds is not touched by timeago.
This commit is contained in:
parent
e69b93c378
commit
efdbae1c1f
3 changed files with 39 additions and 2 deletions
|
@ -41,6 +41,7 @@
|
||||||
refreshMillis: 60000,
|
refreshMillis: 60000,
|
||||||
allowFuture: false,
|
allowFuture: false,
|
||||||
localeTitle: false,
|
localeTitle: false,
|
||||||
|
cutoff: 0,
|
||||||
strings: {
|
strings: {
|
||||||
prefixAgo: null,
|
prefixAgo: null,
|
||||||
prefixFromNow: null,
|
prefixFromNow: null,
|
||||||
|
@ -150,8 +151,12 @@
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
var data = prepareData(this);
|
var data = prepareData(this);
|
||||||
|
var $s = $t.settings;
|
||||||
|
|
||||||
if (!isNaN(data.datetime)) {
|
if (!isNaN(data.datetime)) {
|
||||||
$(this).text(inWords(data.datetime));
|
if ( $s.cutoff == 0 || distance(data.datetime) < $s.cutoff) {
|
||||||
|
$(this).text(inWords(data.datetime));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,12 @@
|
||||||
<p><time id="testTimeTitle" class="timeago" datetime="2012-05-07T10:06:02+02:00" title="May 10, 2012 10:06">May 10, 2012</time></p>
|
<p><time id="testTimeTitle" class="timeago" datetime="2012-05-07T10:06:02+02:00" title="May 10, 2012 10:06">May 10, 2012</time></p>
|
||||||
<p><time id="testTimeTitle2" class="timeago" datetime="2012-05-07T10:06:02+02:00">May 10, 2012</time></p>
|
<p><time id="testTimeTitle2" class="timeago" datetime="2012-05-07T10:06:02+02:00">May 10, 2012</time></p>
|
||||||
|
|
||||||
|
<h2>Cutoff</h2>
|
||||||
|
|
||||||
|
<p>Date that is older than cutoff: <abbr class="timeago cutoff doCutoff" title="1978-12-18">(this should be displayed)</abbr></p>
|
||||||
|
|
||||||
|
<p>Date that is newer than cutoff: <abbr class="timeago loaded cutoff dontCutoff">(you shouldn't see this)</abbr></p>
|
||||||
|
|
||||||
<h2>Errors</h2>
|
<h2>Errors</h2>
|
||||||
|
|
||||||
<p>Bad (letters): <abbr class="bad timeago" title="bleh">(this should be displayed)</abbr>.</p>
|
<p>Bad (letters): <abbr class="bad timeago" title="bleh">(this should be displayed)</abbr>.</p>
|
||||||
|
@ -212,9 +218,13 @@
|
||||||
|
|
||||||
prepareDynamicDates();
|
prepareDynamicDates();
|
||||||
|
|
||||||
$("abbr.timeago").timeago();
|
$("abbr.timeago").not("abbr.cutoff").timeago();
|
||||||
$("time.timeago").timeago();
|
$("time.timeago").timeago();
|
||||||
|
|
||||||
|
loadCutoffSetting();
|
||||||
|
$("abbr.cutoff").timeago();
|
||||||
|
unloadCutoffSetting();
|
||||||
|
|
||||||
var tooltip = $("#testTooltip").data("timeago");
|
var tooltip = $("#testTooltip").data("timeago");
|
||||||
|
|
||||||
$("abbr.todate").each(function () {
|
$("abbr.todate").each(function () {
|
||||||
|
@ -291,6 +301,20 @@
|
||||||
ok(tooltip.datetime, "datetime set");
|
ok(tooltip.datetime, "datetime set");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module("Cutoff");
|
||||||
|
|
||||||
|
test("should not change dates older than cutoff setting", function () {
|
||||||
|
ok(testElements("abbr.doCutoff", function (element) {
|
||||||
|
return (element.html() === "(this should be displayed)");
|
||||||
|
}), "Cutoff 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");
|
||||||
|
}), "Cutoff setting working fine");
|
||||||
|
});
|
||||||
|
|
||||||
module("Tooltip");
|
module("Tooltip");
|
||||||
|
|
||||||
test("should set title to original text contents", function () {
|
test("should set title to original text contents", function () {
|
||||||
|
|
|
@ -22,6 +22,14 @@ function unloadNumbers() {
|
||||||
jQuery.timeago.settings.strings.numbers = [];
|
jQuery.timeago.settings.strings.numbers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadCutoffSetting() {
|
||||||
|
jQuery.timeago.settings.cutoff = 7*24*60*60*1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unloadCutoffSetting() {
|
||||||
|
jQuery.timeago.settings.cutoff = 0;
|
||||||
|
}
|
||||||
|
|
||||||
function loadPigLatin() {
|
function loadPigLatin() {
|
||||||
jQuery.timeago.settings.strings = {
|
jQuery.timeago.settings.strings = {
|
||||||
suffixAgo: "ago-hay",
|
suffixAgo: "ago-hay",
|
||||||
|
|
Loading…
Reference in a new issue