diff --git a/README.markdown b/README.markdown index a9735b33..2539d839 100644 --- a/README.markdown +++ b/README.markdown @@ -4,6 +4,11 @@ Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago") from ISO 8601 formatted dates and times embedded in your HTML (à la microformats). +**If you like this project, please help by donating.** + +* Gittip: https://www.gittip.com/rmm5t/ +* Bitcoin: `1wzBnMjWVZfpiFMc5i2nzKT7sCBaZNfLK` + ## Usage First, load jQuery and the plugin: @@ -13,7 +18,8 @@ First, load jQuery and the plugin: ``` -Now, let's attach it to your timestamps on DOM ready - put this in the head section: +Now, let's attach it to your timestamps on DOM ready - put this in the head +section: ```html @@ -53,7 +59,9 @@ As time passes, the timestamps will automatically update. | Version | Notes | |---------|------------------------------------------------------------------| -| 1.0.x | ([compare][compare-1.0]) locale updates; bug fixes; AMD wrapper | +| 1.2.x | ([compare][compare-1.2]) Added cutoff setting | +| 1.1.x | ([compare][compare-1.1]) Added update function | +| 1.0.x | ([compare][compare-1.0]) locale updates; bug fixes; AMD wrapper | | 0.11.x | ([compare][compare-0.11]) natural rounding; locale updates; | | 0.10.x | ([compare][compare-0.10]) locale updates | | 0.9.x | ([compare][compare-0.9]) microsecond support; bug fixes | @@ -61,6 +69,8 @@ As time passes, the timestamps will automatically update. | 0.7.x | ([compare][compare-0.7]) locale function overrides; unit tests | | ... | ... | +[compare-1.2]: https://github.com/rmm5t/jquery-timeago/compare/v1.1.0...v1.2.0 +[compare-1.1]: https://github.com/rmm5t/jquery-timeago/compare/v1.0.2...v1.1.0 [compare-1.0]: https://github.com/rmm5t/jquery-timeago/compare/v0.11.4...v1.0.2 [compare-0.11]: https://github.com/rmm5t/jquery-timeago/compare/v0.10.1...v0.11.4 [compare-0.10]: https://github.com/rmm5t/jquery-timeago/compare/v0.9.3...v0.10.1 diff --git a/jquery.timeago.js b/jquery.timeago.js index cc17aa7d..bdc54274 100644 --- a/jquery.timeago.js +++ b/jquery.timeago.js @@ -3,7 +3,7 @@ * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). * * @name timeago - * @version 1.1.0 + * @version 1.2.0 * @requires jQuery v1.2.3+ * @author Ryan McGeary * @license MIT License - http://www.opensource.org/licenses/mit-license.php @@ -40,6 +40,8 @@ settings: { refreshMillis: 60000, allowFuture: false, + localeTitle: false, + cutoff: 0, strings: { prefixAgo: null, prefixFromNow: null, @@ -149,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; } @@ -160,7 +166,9 @@ if (!element.data("timeago")) { element.data("timeago", { datetime: $t.datetime(element) }); var text = $.trim(element.text()); - if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) { + if ($t.settings.localeTitle) { + element.attr("title", element.data('timeago').datetime.toLocaleString()); + } else if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) { element.attr("title", text); } } diff --git a/locales/jquery.timeago.ar.js b/locales/jquery.timeago.ar.js index 5fcb8197..9e73d745 100644 --- a/locales/jquery.timeago.ar.js +++ b/locales/jquery.timeago.ar.js @@ -1,32 +1,96 @@ -// Language: Arabic -// Translated By Khaled Attia < Khal3d.com > (function() { - function numpf(num, w, x, y, z) { - if( num == 0 ) { - return w; - } else if( num == 2 ) { - return x; - } else if( num >= 3 && num <= 10) { - return y; // 3:10 - } else { - return z; // 11+ - } + function numpf(n, a) { + return a[plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5]; } - jQuery.timeago.settings.strings = { + +jQuery.timeago.settings.strings = { prefixAgo: "منذ", - prefixFromNow: "يتبقى", + prefixFromNow: "بعد", suffixAgo: null, suffixFromNow: null, // null OR "من الآن" - seconds: function(value) { return numpf(value, "لحظات", "ثانيتين", "%d ثواني", "%d ثانيه"); }, - minute: "دقيقة", - minutes: function(value) { return numpf(value, null, "دقيقتين", "%d دقائق", "%d دقيقة"); }, - hour: "ساعة", - hours: function(value) { return numpf(value, null, "ساعتين", "%d ساعات", "%d ساعة"); }, - day: "يوم", - days: function(value) { return numpf(value, null, "يومين", "%d أيام", "%d يوم"); }, - month: "شهر", - months: function(value) { return numpf(value, null, "شهرين", "%d أشهر", "%d شهر"); }, - year: "سنه", - years: function(value) { return numpf(value, null, "سنتين", "%d سنوات", "%d سنه"); } + second: function(value) { return numpf(value, [ + 'أقل من ثانية', + 'ثانية واحدة', + 'ثانيتين', + '%d ثوانٍ', + '%d ثانية', + '%d ثانية']); }, + seconds: function(value) { return numpf(value, [ + 'أقل من ثانية', + 'ثانية واحدة', + 'ثانيتين', + '%d ثوانٍ', + '%d ثانية', + '%d ثانية']); }, + minute: function(value) { return numpf(value, [ + 'أقل من دقيقة', + 'دقيقة واحدة', + 'دقيقتين', + '%d دقائق', + '%d دقيقة', + 'دقيقة']); }, + minutes: function(value) { return numpf(value, [ + 'أقل من دقيقة', + 'دقيقة واحدة', + 'دقيقتين', + '%d دقائق', + '%d دقيقة', + 'دقيقة']); }, + hour: function(value) { return numpf(value, [ + 'أقل من ساعة', + 'ساعة واحدة', + 'ساعتين', + '%d ساعات', + '%d ساعة', + '%d ساعة']); }, + hours: function(value) { return numpf(value, [ + 'أقل من ساعة', + 'ساعة واحدة', + 'ساعتين', + '%d ساعات', + '%d ساعة', + '%d ساعة']); }, + day: function(value) { return numpf(value, [ + 'أقل من يوم', + 'يوم واحد', + 'يومين', + '%d أيام', + '%d يومًا', + '%d يوم']); }, + days: function(value) { return numpf(value, [ + 'أقل من يوم', + 'يوم واحد', + 'يومين', + '%d أيام', + '%d يومًا', + '%d يوم']); }, + month: function(value) { return numpf(value, [ + 'أقل من شهر', + 'شهر واحد', + 'شهرين', + '%d أشهر', + '%d شهرًا', + '%d شهر']); }, + months: function(value) { return numpf(value, [ + 'أقل من شهر', + 'شهر واحد', + 'شهرين', + '%d أشهر', + '%d شهرًا', + '%d شهر']); }, + year: function(value) { return numpf(value, [ + 'أقل من عام', + 'عام واحد', + '%d عامين', + '%d أعوام', + '%d عامًا']); + }, + years: function(value) { return numpf(value, [ + 'أقل من عام', + 'عام واحد', + 'عامين', + '%d أعوام', + '%d عامًا', + '%d عام']);} }; -})(); \ No newline at end of file +})(); diff --git a/locales/jquery.timeago.ja.js b/locales/jquery.timeago.ja.js index fcf5fdf5..fd81f275 100644 --- a/locales/jquery.timeago.ja.js +++ b/locales/jquery.timeago.ja.js @@ -4,16 +4,16 @@ jQuery.timeago.settings.strings = { prefixFromNow: "今から", suffixAgo: "前", suffixFromNow: "後", - seconds: "ほんの数秒", - minute: "約一分", + seconds: "1 分未満", + minute: "約 1 分", minutes: "%d 分", - hour: "大体一時間", - hours: "大体 %d 時間位", - day: "一日", - days: "%d 日ほど", - month: "大体一ヶ月", - months: "%d ヶ月ほど", - year: "1年前", - years: "%d 年", + hour: "約 1 時間", + hours: "約 %d 時間", + day: "約 1 日", + days: "約 %d 日", + month: "約 1 月", + months: "約 %d 月", + year: "約 1 年", + years: "約 %d 年", wordSeparator: "" -}; \ No newline at end of file +}; diff --git a/locales/jquery.timeago.lt.js b/locales/jquery.timeago.lt.js new file mode 100644 index 00000000..08145557 --- /dev/null +++ b/locales/jquery.timeago.lt.js @@ -0,0 +1,20 @@ +//Lithuanian +jQuery.timeago.settings.strings = { + prefixAgo: "prieš", + prefixFromNow: null, + suffixAgo: null, + suffixFromNow: "nuo dabar", + seconds: "%d sek.", + minute: "min.", + minutes: "%d min.", + hour: "val.", + hours: "%d val.", + day: "1 d.", + days: "%d d.", + month: "mėn.", + months: "%d mėn.", + year: "metus", + years: "%d metus", + wordSeparator: " ", + numbers: [] +}; diff --git a/locales/jquery.timeago.sl.js b/locales/jquery.timeago.sl.js new file mode 100644 index 00000000..e546c0d5 --- /dev/null +++ b/locales/jquery.timeago.sl.js @@ -0,0 +1,44 @@ +// Slovenian with support for dual +(function () { + var numpf; + numpf = function (n, d, m) { + if (n == 2) { + return d; + } else { + return m; + } + }; + + jQuery.timeago.settings.strings = { + prefixAgo: "pred", + prefixFromNow: "čez", + suffixAgo: null, + suffixFromNow: null, + second: "sekundo", + seconds: function (value) { + return numpf(value, "%d sekundama", "%d sekundami"); + }, + minute: "minuto", + minutes: function (value) { + return numpf(value, "%d minutama", "%d minutami"); + }, + hour: "uro", + hours: function (value) { + return numpf(value, "%d urama", "%d urami"); + }, + day: "dnevom", + days: function (value) { + return numpf(value, "%d dnevi", "%d dnevi"); + }, + month: "enim mescem", + months: function (value) { + return numpf(value, "%d mesecema", "%d meseci"); + }, + year: "enim letom", + years: function (value) { + return numpf(value, "%d letoma", "%d leti"); + }, + wordSeparator: " " + }; + +}).call(this); diff --git a/test/index.html b/test/index.html index cee81f9e..e0e105dd 100644 --- a/test/index.html +++ b/test/index.html @@ -63,6 +63,12 @@
Date that is older than cutoff: (this should be displayed)
+ +Date that is newer than cutoff: (you shouldn't see this)
+Bad (letters): (this should be displayed).
@@ -212,9 +218,13 @@