Skip to content

Commit

Permalink
use this fork of jquery.timeago (https://github.com/deceze/jquery-tim…
Browse files Browse the repository at this point in the history
…eago) so we can specify space or not between time words and suffix
  • Loading branch information
ashchan committed Dec 6, 2011
1 parent a882661 commit 4979552
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions vendor/assets/javascripts/jquery.timeago.js
Expand Up @@ -45,7 +45,8 @@
months: "%d months",
year: "about a year",
years: "%d years",
numbers: []
numbers: [],
formatter: null
}
},
inWords: function(distanceMillis) {
Expand All @@ -68,7 +69,7 @@

function substitute(stringOrFunction, number) {
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
var value = ($l.numbers && $l.numbers[number]) || number;
var value = $.isFunction($l.numbers) ? $l.numbers(number) : (($l.numbers && $l.numbers[number]) || number);
return string.replace(/%d/i, value);
}

Expand All @@ -84,7 +85,7 @@
years < 2 && substitute($l.year, 1) ||
substitute($l.years, Math.floor(years));

return $.trim([prefix, words, suffix].join(" "));
return $.isFunction($l.formatter) ? $l.formatter(prefix, words, suffix) : $.trim([prefix, words, suffix].join(" "));
},
parse: function(iso8601) {
var s = $.trim(iso8601);
Expand Down
7 changes: 5 additions & 2 deletions vendor/assets/javascripts/jquery.timeago.settings.js.erb
Expand Up @@ -16,7 +16,8 @@
months: "%d月",
year: "1年",
years: "%d年",
numbers: []
numbers: [],
formatter: function(prefix, words, suffix) { return [prefix, words, suffix].join(""); }
},
"zh-TW": {
prefixAgo: null,
Expand All @@ -34,12 +35,14 @@
months: "%d月",
year: "1年",
years: "%d年",
numbers: []
numbers: [],
formatter: function(prefix, words, suffix) { return [prefix, words, suffix].join(""); }
}
};

var localized = strings["<%= I18n.locale %>"];
if (localized) {
jQuery.timeago.settings.strings = localized;
}

})();

0 comments on commit 4979552

Please sign in to comment.