Renamed wordSep setting to wordSeparator and added tests

This commit is contained in:
Ryan McGeary 2012-03-03 15:15:18 -05:00
parent d11a9ccb6d
commit e085a6f28d
3 changed files with 22 additions and 4 deletions

View file

@ -45,7 +45,7 @@
months: "%d months", months: "%d months",
year: "about a year", year: "about a year",
years: "%d years", years: "%d years",
wordSep: " ", wordSeparator: " ",
numbers: [] numbers: []
} }
}, },
@ -84,7 +84,7 @@
years < 2 && substitute($l.year, 1) || years < 2 && substitute($l.year, 1) ||
substitute($l.years, Math.floor(years)); substitute($l.years, Math.floor(years));
return $.trim([prefix, words, suffix].join($l.wordSep)); return $.trim([prefix, words, suffix].join($l.wordSeparator));
}, },
parse: function(iso8601) { parse: function(iso8601) {
var s = $.trim(iso8601); var s = $.trim(iso8601);

View file

@ -130,6 +130,8 @@
<li><abbr id="testYoungOldSettings1" class="toyoungold" title="504576000"></abbr> [5840 days]</li> <li><abbr id="testYoungOldSettings1" class="toyoungold" title="504576000"></abbr> [5840 days]</li>
<li><abbr id="testYoungOldSettings2" class="toyoungold" title="2018304000"></abbr> [23360 days]</li> <li><abbr id="testYoungOldSettings2" class="toyoungold" title="2018304000"></abbr> [23360 days]</li>
<li><abbr id="testNoSpaces1" class="nospaces" title="120"></abbr> [120 sec]</li>
<li><abbr id="testLatinSettings1" class="tolatin" title="-7200"></abbr> [-120 min]</li> <li><abbr id="testLatinSettings1" class="tolatin" title="-7200"></abbr> [-120 min]</li>
<li><abbr id="testLatinSettings2" class="tolatin" title="-60"></abbr> [-60 sec]</li> <li><abbr id="testLatinSettings2" class="tolatin" title="-60"></abbr> [-60 sec]</li>
<li><abbr id="testLatinSettings3" class="tolatin" title="-30"></abbr> [-30 sec]</li> <li><abbr id="testLatinSettings3" class="tolatin" title="-30"></abbr> [-30 sec]</li>
@ -230,6 +232,9 @@
loadYoungOldYears(); loadYoungOldYears();
$("abbr.toyoungold").each(toWords); $("abbr.toyoungold").each(toWords);
loadNoSpaces();
$("abbr.nospaces").each(toWords);
loadPigLatin(); loadPigLatin();
$("abbr.tolatin").each(toWords); $("abbr.tolatin").each(toWords);
@ -508,6 +513,10 @@
ok($("#testNumbersSettings2").html().match(/^nine minutes/), "Settings correctly applied"); ok($("#testNumbersSettings2").html().match(/^nine minutes/), "Settings correctly applied");
ok($("#testNumbersSettings3").html().match(/^10 minutes/), "Settings correctly applied"); ok($("#testNumbersSettings3").html().match(/^10 minutes/), "Settings correctly applied");
}); });
test("wordSeparator", function () {
ok($("#testNoSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
});
})(jQuery); })(jQuery);
//]]> //]]>
</script> </script>

View file

@ -36,7 +36,8 @@ function loadPigLatin() {
month: "about-hay a-hay onth-may", month: "about-hay a-hay onth-may",
months: "%d onths-may", months: "%d onths-may",
year: "about-hay a-hay ear-yay", year: "about-hay a-hay ear-yay",
years: "%d years-yay" years: "%d years-yay",
wordSeparator: " "
}; };
} }
@ -71,7 +72,8 @@ function loadRussian() {
month: "месяц", month: "месяц",
months: function(value) { return numpf(value, "%d месяц", "%d месяца", "%d месяцев"); }, months: function(value) { return numpf(value, "%d месяц", "%d месяца", "%d месяцев"); },
year: "год", year: "год",
years: function(value) { return numpf(value, "%d год", "%d года", "%d лет"); } years: function(value) { return numpf(value, "%d год", "%d года", "%d лет"); },
wordSeparator: " "
}; };
})(); })();
} }
@ -95,6 +97,13 @@ function loadMillis() {
}; };
} }
function loadNoSpaces() {
jQuery.extend(jQuery.timeago.settings.strings, {
minutes: "%dminutes",
wordSeparator: ""
});
}
function loadYoungOldYears() { function loadYoungOldYears() {
jQuery.extend(jQuery.timeago.settings.strings, { jQuery.extend(jQuery.timeago.settings.strings, {
years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; } years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; }