From 3109ef5d86467ceb27d04dd0a7be089d9bc4c5e8 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Sun, 28 Feb 2010 14:24:23 -0500 Subject: [PATCH] Added support for using words instead of figures for a range of numbers * The intention is to give the ability to support words instead of figures for numbers up to ten. * Credit goes to Nick Zadrozny (nzadrozny) for the idea --- jquery.timeago.js | 14 ++++++++------ test/index.html | 14 ++++++++++++++ test/test_helpers.js | 7 +++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/jquery.timeago.js b/jquery.timeago.js index 1b327c6..f0e6b55 100644 --- a/jquery.timeago.js +++ b/jquery.timeago.js @@ -40,7 +40,8 @@ month: "about a month", months: "%d months", year: "about a year", - years: "%d years" + years: "%d years", + numbers: [] } }, inWords: function(distanceMillis) { @@ -61,6 +62,12 @@ var days = hours / 24; var years = days / 365; + function substitute(stringOrFunction, number) { + var string = $.isFunction(stringOrFunction) ? stringOrFunction(number) : stringOrFunction; + var value = ($l.numbers && $l.numbers[number]) || number; + return string.replace(/%d/i, value); + } + var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) || seconds < 90 && substitute($l.minute, 1) || minutes < 45 && substitute($l.minutes, Math.round(minutes)) || @@ -127,11 +134,6 @@ return (new Date().getTime() - date.getTime()); } - function substitute(stringOrFunction, value) { - var string = $.isFunction(stringOrFunction) ? stringOrFunction(value) : stringOrFunction; - return string.replace(/%d/i, value); - } - // fix for IE6 suckage document.createElement("abbr"); document.createElement("time"); diff --git a/test/index.html b/test/index.html index a87bf11..541edf2 100644 --- a/test/index.html +++ b/test/index.html @@ -120,6 +120,10 @@

Settings