mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2025-02-17 00:20:32 -05:00
Merge pull request #129 from shish/cutoff-setting
Cutoff setting for leaving older dates alone. [Rebase]
This commit is contained in:
commit
2f2fb8f39a
3 changed files with 39 additions and 2 deletions
|
@ -41,6 +41,7 @@
|
|||
refreshMillis: 60000,
|
||||
allowFuture: false,
|
||||
localeTitle: false,
|
||||
cutoff: 0,
|
||||
strings: {
|
||||
prefixAgo: null,
|
||||
prefixFromNow: null,
|
||||
|
@ -150,8 +151,12 @@
|
|||
|
||||
function refresh() {
|
||||
var data = prepareData(this);
|
||||
var $s = $t.settings;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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="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>
|
||||
|
||||
<p>Bad (letters): <abbr class="bad timeago" title="bleh">(this should be displayed)</abbr>.</p>
|
||||
|
@ -212,9 +218,13 @@
|
|||
|
||||
prepareDynamicDates();
|
||||
|
||||
$("abbr.timeago").timeago();
|
||||
$("abbr.timeago").not("abbr.cutoff").timeago();
|
||||
$("time.timeago").timeago();
|
||||
|
||||
loadCutoffSetting();
|
||||
$("abbr.cutoff").timeago();
|
||||
unloadCutoffSetting();
|
||||
|
||||
var tooltip = $("#testTooltip").data("timeago");
|
||||
|
||||
$("abbr.todate").each(function () {
|
||||
|
@ -291,6 +301,20 @@
|
|||
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");
|
||||
|
||||
test("should set title to original text contents", function () {
|
||||
|
|
|
@ -22,6 +22,14 @@ function unloadNumbers() {
|
|||
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() {
|
||||
jQuery.timeago.settings.strings = {
|
||||
suffixAgo: "ago-hay",
|
||||
|
|
Loading…
Reference in a new issue