Skip to content

Commit bd42f80

Browse files
Interpret null wordSeparator as empty string
1 parent 7a05219 commit bd42f80

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

jquery.timeago.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,16 @@
8686
years < 1.5 && substitute($l.year, 1) ||
8787
substitute($l.years, Math.round(years));
8888

89-
var separator = $l.wordSeparator === undefined ? " " : $l.wordSeparator;
89+
switch ($l.wordSeparator) {
90+
case undefined:
91+
var separator = " ";
92+
break;
93+
case null:
94+
var separator = "";
95+
break;
96+
default:
97+
var separator = $l.wordSeparator;
98+
}
9099
return $.trim([prefix, words, suffix].join(separator));
91100
},
92101
parse: function(iso8601) {

test/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ <h2>Settings</h2>
139139
<li><abbr id="testYoungOldSettings2" class="toyoungold" title="2018304000"></abbr> [23360 days]</li>
140140

141141
<li><abbr id="testNoSpaces1" class="nospaces" title="120"></abbr> [120 sec]</li>
142+
<li><abbr id="testNullSpaces1" class="nullspaces" title="120"></abbr> [120 sec]</li>
142143

143144
<li><abbr id="testLatinSettings1" class="tolatin" title="-7200"></abbr> [-120 min]</li>
144145
<li><abbr id="testLatinSettings2" class="tolatin" title="-60"></abbr> [-60 sec]</li>
@@ -243,6 +244,9 @@ <h2>Settings</h2>
243244
loadNoSpaces();
244245
$("abbr.nospaces").each(toWords);
245246

247+
loadNullSpaces();
248+
$("abbr.nullspaces").each(toWords);
249+
246250
loadPigLatin();
247251
$("abbr.tolatin").each(toWords);
248252

@@ -562,6 +566,7 @@ <h2>Settings</h2>
562566

563567
test("wordSeparator", function () {
564568
ok($("#testNoSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
569+
ok($("#testNullSpaces1").html().match(/^2minutesago$/), "Settings correctly applied");
565570
});
566571
})(jQuery);
567572
//]]>

test/test_helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ function loadNoSpaces() {
102102
});
103103
}
104104

105+
function loadNullSpaces() {
106+
jQuery.extend(jQuery.timeago.settings.strings, {
107+
minutes: "%dminutes",
108+
wordSeparator: null
109+
});
110+
}
111+
105112
function loadYoungOldYears() {
106113
jQuery.extend(jQuery.timeago.settings.strings, {
107114
years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; }

0 commit comments

Comments
 (0)