Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rmm5t/jquery-timeago
base: v0.7.2
...
head fork: rmm5t/jquery-timeago
compare: v0.8.2
Checking mergeability… Don't worry, you can still create the pull request.
  • 16 commits
  • 5 files changed
  • 1 commit comment
  • 2 contributors
View
6 README.markdown
@@ -15,7 +15,7 @@ Now, let's attach it to your timestamps on DOM ready:
<pre>
jQuery(document).ready(function() {
- jQuery('abbr[class*=timeago]').timeago();
+ jQuery("abbr.timeago").timeago();
});
</pre>
@@ -25,7 +25,7 @@ This will turn all abbr elements with a class of timeago and an ISO 8601 timesta
into something like this:
- <abbr class="timeago" title="2008-07-17T09:24:17Z">about 1 day ago</abbr>
+ <abbr class="timeago" title="July 17, 2008">about 1 day ago</abbr>
As time passes, the timestamps will automatically update.
@@ -41,4 +41,4 @@ As time passes, the timestamps will automatically update.
[MIT License](http://www.opensource.org/licenses/mit-license.php)
-Copyright (c) 2008-2009, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
+Copyright (c) 2008-2010, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
View
30 index.html
@@ -5,12 +5,13 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="microid" content="mailto+http:sha1:566841e568e84b46c92d2291b44b836dfddc5c42" />
<title>timeago: a jQuery plugin</title>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script src="jquery.timeago.js" type="text/javascript"></script>
- <script src="test.js" type="text/javascript"></script>
+ <script src="test/test_helpers.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
- $('abbr[class*=timeago]').timeago();
+ prepareDynamicDates();
+ $("abbr.timeago").timeago();
$("#prog_date").text(jQuery.timeago(new Date()));
$("#prog_string").text(jQuery.timeago("2008-07-17"));
@@ -54,8 +55,9 @@
timestamps (e.g. "4 minutes ago" or "about 1 day ago"). <a href="jquery.timeago.js">Download</a>, view
the examples, and enjoy.
</p>
+ <noscript><p class="example"><strong>Turn on javascript, loser!</strong></p></noscript>
<p class="example">
- You opened this page <abbr class="loaded timeago">sometime before now <span class="help">(turn on javascript, loser)</span></abbr>. <span class="help">(This will update every minute. Wait for it.)</span>
+ You opened this page <abbr class="loaded timeago">when you opened the page</abbr>. <span class="help">(This will update every minute. Wait for it.)</span>
</p>
<p class="example">
This page was last modified <abbr class="modified timeago">sometime before now [browser might not support document.lastModified]</abbr>.
@@ -84,7 +86,7 @@
</p>
<pre>
jQuery(document).ready(function() {
- jQuery('abbr[class*=timeago]').timeago();
+ jQuery("abbr.timeago").timeago();
});</pre>
<p class="how">
This will turn all <tt>abbr</tt> elements with a class
@@ -96,7 +98,7 @@
into something like this:
</p>
<pre>
-&lt;abbr class=&quot;timeago&quot; title=&quot;2008-07-17T09:24:17Z&quot;&gt;<em><abbr class="timeago" title="2008-07-17T09:24:17Z">time ago</abbr></em>&lt;/abbr&gt;</pre>
+&lt;abbr class=&quot;timeago&quot; title=&quot;July 17, 2008&quot;&gt;<em><abbr class="timeago" title="2008-07-17T09:24:17Z">time ago</abbr></em>&lt;/abbr&gt;</pre>
<p>
which yields: <abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>. As time passes, the timestamps will automatically update.
</p>
@@ -144,6 +146,20 @@
Timeago was conceived <abbr class="timeago" title="2008-07-17T02:30:00-0500">on July 17, 2008</abbr>. <span class="help">(Yup, that's powered by timeago too)</span>
</p>
+ <h3>What else?</h3>
+ <p class="example">
+ HTML5 has a new <tt>time</tt> tag and timeago supports it too.
+ </p>
+ <pre>
+&lt;time class=&quot;<em>timeago</em>&quot; datetime=&quot;<em>2008-07-17T09:24:17Z</em>&quot;&gt;July 17, 2008&lt;/time&gt;</pre>
+ <p class="how">
+ Attach timeago like so:
+ </p>
+ <pre>
+jQuery(document).ready(function() {
+ jQuery("time.timeago").timeago();
+});</pre>
+
<h3>Huh?</h3>
<p class="last">
Need a Rails helper to make those fancy microformat <tt>abbr</tt> tags? Fine, here ya go:
@@ -160,7 +176,7 @@
<a href="http://www.opensource.org/licenses/mit-license.php">MIT
License</a>
</div>
- Copyright &copy; 2008-2009 <a href="http://ryan.mcgeary.org">Ryan McGeary</a>
+ Copyright &copy; 2008-2010 <a href="http://ryan.mcgeary.org">Ryan McGeary</a>
(<a href="http://twitter.com/rmm5t">@rmm5t</a>)
</div>
View
33 jquery.timeago.js
@@ -1,6 +1,6 @@
/*
- * timeago: a jQuery plugin, version: 0.7.2 (2009-07-30)
- * @requires jQuery v1.2 or later
+ * timeago: a jQuery plugin, version: 0.8.2 (2010-02-16)
+ * @requires jQuery v1.2.3 or later
*
* 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").
@@ -11,13 +11,13 @@
* Licensed under the MIT:
* http://www.opensource.org/licenses/mit-license.php
*
- * Copyright (c) 2008-2009, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
+ * Copyright (c) 2008-2010, Ryan McGeary (ryanonjavascript -[at]- mcgeary [*dot*] org)
*/
(function($) {
$.timeago = function(timestamp) {
if (timestamp instanceof Date) return inWords(timestamp);
else if (typeof timestamp == "string") return inWords($.timeago.parse(timestamp));
- else return inWords($.timeago.parse($(timestamp).attr("title")));
+ else return inWords($.timeago.datetime(timestamp));
};
var $t = $.timeago;
@@ -83,6 +83,12 @@
s = s.replace(/T/," ").replace(/Z/," UTC");
s = s.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
return new Date(s);
+ },
+ datetime: function(elem) {
+ // jQuery's `is()` doesn't play well with HTML5 in IE
+ var isTime = $(elem).get(0).tagName.toLowerCase() == "time"; // $(elem).is("time");
+ var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title");
+ return $t.parse(iso8601);
}
});
@@ -98,13 +104,23 @@
};
function refresh() {
- var date = $t.parse(this.title);
- if (!isNaN(date)) {
- $(this).text(inWords(date));
+ var data = prepareData(this);
+ if (!isNaN(data.datetime)) {
+ $(this).text(inWords(data.datetime));
}
return this;
}
+ function prepareData(element) {
+ element = $(element);
+ if (!element.data("timeago")) {
+ element.data("timeago", { datetime: $t.datetime(element) });
+ var text = $.trim(element.text());
+ if (text.length > 0) element.attr("title", text);
+ }
+ return element.data("timeago");
+ }
+
function inWords(date) {
return $t.inWords(distance(date));
}
@@ -119,5 +135,6 @@
}
// fix for IE6 suckage
- document.createElement('abbr');
+ document.createElement("abbr");
+ document.createElement("time");
})(jQuery);
View
372 test/index.html
@@ -4,7 +4,7 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- use http://code.jquery.com/jquery-latest.js for the latest jQuery -->
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<!-- http://dev.jquery.com/view/trunk/qunit/testrunner.js -->
<script src="testrunner.js" type="text/javascript"></script>
@@ -24,7 +24,7 @@ <h2 id="userAgent"></h2>
<div id="main">
<h2>Short term</h2>
- <p>You opened this page <abbr class="loaded timeago testShortTerm">sometime before now</abbr>.</p>
+ <p>You opened this page <abbr class="loaded timeago testShortTerm">(you shouldn't see this)</abbr>.</p>
<p>
This page was last modified <abbr class="modified timeago">sometime before
@@ -66,12 +66,15 @@ <h2 id="userAgent"></h2>
<h2>Other formats</h2>
- <p>Date only: <abbr class="timeago" title="2008-02-26">(you shouldn't see this)</abbr>.</p>
+ <p>Date only (abbr element): <abbr class="timeago" title="2008-02-26">(you shouldn't see this)</abbr>.</p>
+ <p>Date only (time element): <time class="timeago" datetime="2008-02-26">(you shouldn't see this)</time>.</p>
+ <p>Date only (friendly tooltip): <abbr id="testTooltip" class="timeago" title="2008-02-26">February 26th</abbr>.</p>
+ <p>Date only (default tooltip): <abbr id="defaultTooltip" class="timeago" title="2008-02-26"> </abbr>.</p>
<h2>Errors</h2>
<p>Bad (letters): <abbr class="bad timeago" title="bleh">(this should be displayed)</abbr>.</p>
- <p>Bad (numbers): <abbr class="bad timeago" title="1234">(this should be displayed)</abbr>.</p>
+ <p>Bad (numbers): <abbr class="bad timeago" title="91234">(this should be displayed)</abbr>.</p>
<p>Bad (blank): <abbr class="bad timeago" title="">(this should be displayed)</abbr>.</p>
<p>Bad (missing): <abbr class="bad timeago">(this should be displayed)</abbr>.</p>
@@ -166,82 +169,10 @@ <h2 id="userAgent"></h2>
</ul>
</div>
+ <script src="test_helpers.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
(function ($) {
- function zeropad(num) {
- return ((num < 10) ? '0' : '') + num;
- }
-
- function iso8601(date) {
- return date.getUTCFullYear()
- + '-' + zeropad(date.getUTCMonth() + 1)
- + '-' + zeropad(date.getUTCDate())
- + 'T' + zeropad(date.getUTCHours())
- + ':' + zeropad(date.getUTCMinutes())
- + ':' + zeropad(date.getUTCSeconds()) + 'Z';
- }
-
- function loadPigLatin() {
- $.timeago.settings.strings = {
- suffixAgo : 'ago-hay',
- suffixFromNow: 'omNow-fray',
- seconds : 'ess-lay an-thay a-hay inute-may',
- minute : 'about-hay a-hay inute-may',
- minutes : '%d inutes-may',
- hour : 'about-hay an-hay hour-hay',
- hours : 'about-hay %d hours-hay',
- day : 'a-hay ay-day',
- days : '%d ays-day',
- month : 'about-hay a-hay onth-may',
- months : '%d onths-may',
- year : 'about-hay a-hay ear-yay',
- years : '%d years-yay'
- };
- }
-
- function loadRussian() {
- (function() {
- function numpf(n, f, s, t) {
- // f - 1, 21, 31, ...
- // s - 2-4, 22-24, 32-34 ...
- // t - 5-20, 25-30, ...
- var n10 = n % 10;
- if ((n10 == 1) && ((n == 1) || (n > 20) )) {
- return f;
- } else if ((n10 > 1) && (n10 < 5) && ((n > 20) || (n < 10))) {
- return s;
- } else {
- return t;
- }
- }
-
- $.timeago.settings.strings = {
- prefixAgo: null,
- prefixFromNow: 'через',
- suffixAgo: 'назад',
- suffixFromNow: null,
- seconds: 'меньше минуты',
- minute: 'минуту',
- minutes: function(value) { return numpf(value, '%d минута', '%d минуты', '%d минут'); },
- hour: 'час',
- hours: function(value) { return numpf(value, '%d час', '%d часа', '%d часов'); },
- day: 'день',
- days: function(value) { return numpf(value, '%d день', '%d дня', '%d дней'); },
- month: 'месяц',
- months: function(value) { return numpf(value, '%d месяц', '%d месяца', '%d месяцев'); },
- year: 'год',
- years: function(value) { return numpf(value, '%d год', '%d года', '%d лет'); }
- };
- })();
- }
-
- function loadYoungOldYears() {
- $.extend($.timeago.settings.strings, {
- years: function(value) { return (value < 21) ? '%d young years' : '%d old years'; }
- });
- }
-
function testElements(selector, test) {
var elements = $(selector);
var numberOfTests = elements.length;
@@ -261,254 +192,279 @@ <h2 id="userAgent"></h2>
$.timeago.settings.allowFuture = true;
- $('abbr.loaded').attr('title', iso8601(new Date()));
- $('abbr.modified').attr('title', iso8601(new Date(document.lastModified)));
+ prepareDynamicDates();
+
+ $("abbr.timeago").timeago();
+ $("time.timeago").timeago();
- $('abbr.timeago').timeago();
+ var tooltip = $("#testTooltip").data("timeago");
- $('abbr.todate').each(function () {
+ $("abbr.todate").each(function () {
var date = $.timeago.parse(this.title);
$(this).text(date.toUTCString());
});
- $('abbr.towords').each(toWords);
+ $("abbr.towords").each(toWords);
loadYoungOldYears();
- $('abbr.toyoungold').each(toWords);
+ $("abbr.toyoungold").each(toWords);
loadPigLatin();
- $('abbr.tolatin').each(toWords);
+ $("abbr.tolatin").each(toWords);
loadRussian();
- $('abbr.torussian').each(toWords);
+ $("abbr.torussian").each(toWords);
- module('Valid date');
+ module("Valid date");
- test('Text in abbr tag should be replaced', function () {
- ok(testElements('abbr.timeago', function (element) {
+ test("Text in abbr tag should be replaced", function () {
+ ok(testElements("abbr.timeago", function (element) {
return (element.html() !== "(you shouldn't see this)");
- }), 'All text was replaced');
+ }), "All text was replaced");
});
- module('Invalid date');
+ test("Text in time tag should be replaced", function () {
+ ok(testElements("time.timeago", function (element) {
+ return (element.html() !== "(you shouldn't see this)");
+ }), "All text was replaced");
+ });
+
+ module("Invalid date");
- test('Text in abbr should not be replaced', function () {
- ok(testElements('abbr.bad', function (element) {
- return (element.html() === '(this should be displayed)');
- }), 'No text was replaced');
+ test("Text in abbr should not be replaced", function () {
+ ok(testElements("abbr.bad", function (element) {
+ return (element.html() === "(this should be displayed)");
+ }), "No text was replaced");
});
- module('Short term');
+ module("Short term");
test("Dates shorter than a minute should be replaced with short term text", function () {
- ok(testElements('abbr.testShortTerm', function (element) {
- return (element.html() === 'less than a minute ago');
- }), 'All short term dates correctly parsed');
+ ok(testElements("abbr.testShortTerm", function (element) {
+ return (element.html() === "less than a minute ago");
+ }), "All short term dates correctly parsed");
});
- module('Long term');
+ module("Long term");
test("Dates older than one year should contain the word 'year'", function () {
- ok(testElements('abbr.testLongTerm', function (element) {
+ ok(testElements("abbr.testLongTerm", function (element) {
return (element.html().match(/year/));
- }), 'All long term dates correctly parsed');
+ }), "All long term dates correctly parsed");
+ });
+
+ module("Data object");
+
+ test("should set timeago data object", function () {
+ ok(tooltip, "data set");
+ ok(tooltip.datetime, "datetime set");
+ });
+
+ module("Tooltip");
+
+ test("should set title to original text contents", function () {
+ ok($("#testTooltip").attr("title") == "February 26th", "correctly set");
+ });
+
+ test("should leave title alone if no text text content", function () {
+ ok($("#defaultTooltip").attr("title") == "2008-02-26", "correctly set");
});
- module('Parsing');
+ module("Parsing");
// Note, different browsers behave slightly different
var correctMatch = /Mon, 18 Dec 1978 17:17:00 GMT/;
- test('From Z', function () {
- ok(($('#testParsing1').html().match(correctMatch)), 'Correctly parsed');
+ test("From Z", function () {
+ ok(($("#testParsing1").html().match(correctMatch)), "Correctly parsed");
});
- test('From -00:00', function () {
- ok(($('#testParsing2').html().match(correctMatch)), 'Correctly parsed');
+ test("From -00:00", function () {
+ ok(($("#testParsing2").html().match(correctMatch)), "Correctly parsed");
});
- test('From -05:00', function () {
- ok(($('#testParsing3').html().match(correctMatch)), 'Correctly parsed');
+ test("From -05:00", function () {
+ ok(($("#testParsing3").html().match(correctMatch)), "Correctly parsed");
});
- test('From -0500', function () {
- ok(($('#testParsing4').html().match(correctMatch)), 'Correctly parsed');
+ test("From -0500", function () {
+ ok(($("#testParsing4").html().match(correctMatch)), "Correctly parsed");
});
- test('From +09:00', function () {
- ok(($('#testParsing5').html().match(correctMatch)), 'Correctly parsed');
+ test("From +09:00", function () {
+ ok(($("#testParsing5").html().match(correctMatch)), "Correctly parsed");
});
- test('From +0900', function () {
- ok(($('#testParsing6').html().match(correctMatch)), 'Correctly parsed');
+ test("From +0900", function () {
+ ok(($("#testParsing6").html().match(correctMatch)), "Correctly parsed");
});
- test('From blank TZ', function () {
- ok(($('#testParsing7').html().match(/Mon, 18 Dec 1978 \d\d:17:00 GMT/)), 'Correctly parsed, assumed local time');
+ test("From blank TZ", function () {
+ ok(($("#testParsing7").html().match(/Mon, 18 Dec 1978 \d\d:17:00 GMT/)), "Correctly parsed, assumed local time");
});
- module('Wording');
+ module("Wording");
- test('-120 min', function () {
- ok(($('#testWording1').html() === 'about 2 hours from now'), 'Correctly parsed');
+ test("-120 min", function () {
+ ok(($("#testWording1").html() === "about 2 hours from now"), "Correctly parsed");
});
- test('-60 sec', function () {
- ok(($('#testWording2').html() === 'about a minute from now'), 'Correctly parsed');
+ test("-60 sec", function () {
+ ok(($("#testWording2").html() === "about a minute from now"), "Correctly parsed");
});
- test('-30 sec', function () {
- ok(($('#testWording3').html() === 'less than a minute from now'), 'Correctly parsed');
+ test("-30 sec", function () {
+ ok(($("#testWording3").html() === "less than a minute from now"), "Correctly parsed");
});
- test('-1 sec', function () {
- ok(($('#testWording4').html() === 'less than a minute from now'), 'Correctly parsed');
+ test("-1 sec", function () {
+ ok(($("#testWording4").html() === "less than a minute from now"), "Correctly parsed");
});
- test('0 sec', function () {
- ok(($('#testWording5').html() === 'less than a minute ago'), 'Correctly parsed');
+ test("0 sec", function () {
+ ok(($("#testWording5").html() === "less than a minute ago"), "Correctly parsed");
});
- test('30 sec', function () {
- ok(($('#testWording6').html() === 'less than a minute ago'), 'Correctly parsed');
+ test("30 sec", function () {
+ ok(($("#testWording6").html() === "less than a minute ago"), "Correctly parsed");
});
- test('45 sec', function () {
- ok(($('#testWording7').html() === 'about a minute ago'), 'Correctly parsed');
+ test("45 sec", function () {
+ ok(($("#testWording7").html() === "about a minute ago"), "Correctly parsed");
});
- test('90 sec', function () {
- ok(($('#testWording8').html() === '2 minutes ago'), 'Correctly parsed');
+ test("90 sec", function () {
+ ok(($("#testWording8").html() === "2 minutes ago"), "Correctly parsed");
});
- test('120 sec', function () {
- ok(($('#testWording9').html() === '2 minutes ago'), 'Correctly parsed');
+ test("120 sec", function () {
+ ok(($("#testWording9").html() === "2 minutes ago"), "Correctly parsed");
});
- test('45 min', function () {
- ok(($('#testWording10').html() === 'about an hour ago'), 'Correctly parsed');
+ test("45 min", function () {
+ ok(($("#testWording10").html() === "about an hour ago"), "Correctly parsed");
});
- test('89 min', function () {
- ok(($('#testWording11').html() === 'about an hour ago'), 'Correctly parsed');
+ test("89 min", function () {
+ ok(($("#testWording11").html() === "about an hour ago"), "Correctly parsed");
});
- test('90 min', function () {
- ok(($('#testWording12').html() === 'about 2 hours ago'), 'Correctly parsed');
+ test("90 min", function () {
+ ok(($("#testWording12").html() === "about 2 hours ago"), "Correctly parsed");
});
- test('120 min', function () {
- ok(($('#testWording13').html() === 'about 2 hours ago'), 'Correctly parsed');
+ test("120 min", function () {
+ ok(($("#testWording13").html() === "about 2 hours ago"), "Correctly parsed");
});
- test('1380 min', function () {
- ok(($('#testWording14').html() === 'about 23 hours ago'), 'Correctly parsed');
+ test("1380 min", function () {
+ ok(($("#testWording14").html() === "about 23 hours ago"), "Correctly parsed");
});
- test('25 hours', function () {
- ok(($('#testWording15').html() === 'a day ago'), 'Correctly parsed');
+ test("25 hours", function () {
+ ok(($("#testWording15").html() === "a day ago"), "Correctly parsed");
});
- test('48 hours', function () {
- ok(($('#testWording16').html() === '2 days ago'), 'Correctly parsed');
+ test("48 hours", function () {
+ ok(($("#testWording16").html() === "2 days ago"), "Correctly parsed");
});
- test('696 hours', function () {
- ok(($('#testWording17').html() === '29 days ago'), 'Correctly parsed');
+ test("696 hours", function () {
+ ok(($("#testWording17").html() === "29 days ago"), "Correctly parsed");
});
- test('30 days', function () {
- ok(($('#testWording18').html() === 'about a month ago'), 'Correctly parsed');
+ test("30 days", function () {
+ ok(($("#testWording18").html() === "about a month ago"), "Correctly parsed");
});
- test('190 days', function () {
- ok(($('#testWording19').html() === '6 months ago'), 'Correctly parsed');
+ test("190 days", function () {
+ ok(($("#testWording19").html() === "6 months ago"), "Correctly parsed");
});
- test('366 days', function () {
- ok(($('#testWording20').html() === 'about a year ago'), 'Correctly parsed');
+ test("366 days", function () {
+ ok(($("#testWording20").html() === "about a year ago"), "Correctly parsed");
});
- test('1095 days', function () {
- ok(($('#testWording21').html() === '3 years ago'), 'Correctly parsed');
+ test("1095 days", function () {
+ ok(($("#testWording21").html() === "3 years ago"), "Correctly parsed");
});
- module('Settings');
+ module("Settings");
- test('suffixFromNow', function () {
- ok($('#testLatinSettings1').html().match(/omNow-fray$/), 'Settings correctly applied');
+ test("suffixFromNow", function () {
+ ok($("#testLatinSettings1").html().match(/omNow-fray$/), "Settings correctly applied");
});
- test('suffixAgo', function () {
- ok($('#testLatinSettings5').html().match(/ago-hay$/), 'Settings correctly applied');
- ok($('#testRussianSettings5').html().match(/назад$/), 'Settings correctly applied');
+ test("suffixAgo", function () {
+ ok($("#testLatinSettings5").html().match(/ago-hay$/), "Settings correctly applied");
+ ok($("#testRussianSettings5").html().match(/назад$/), "Settings correctly applied");
});
- test('prefixFromNow', function () {
- ok($('#testRussianSettings2').html().match(/^через/), 'Settings correctly applied');
+ test("prefixFromNow", function () {
+ ok($("#testRussianSettings2").html().match(/^через/), "Settings correctly applied");
});
- test('seconds', function () {
- ok($('#testLatinSettings5').html().match(/^ess-lay an-thay a-hay inute-may/), 'Settings correctly applied');
- ok($('#testRussianSettings5').html().match(/^меньше минуты/), 'Settings correctly applied');
+ test("seconds", function () {
+ ok($("#testLatinSettings5").html().match(/^ess-lay an-thay a-hay inute-may/), "Settings correctly applied");
+ ok($("#testRussianSettings5").html().match(/^меньше минуты/), "Settings correctly applied");
});
- test('minute', function () {
- ok($('#testLatinSettings7').html().match(/^about-hay a-hay inute-may/), 'Settings correctly applied');
- ok($('#testRussianSettings7').html().match(/^минуту/), 'Settings correctly applied');
+ test("minute", function () {
+ ok($("#testLatinSettings7").html().match(/^about-hay a-hay inute-may/), "Settings correctly applied");
+ ok($("#testRussianSettings7").html().match(/^минуту/), "Settings correctly applied");
});
- test('minutes', function () {
- ok($('#testLatinSettings8').html().match(/^2 inutes-may/), 'Settings correctly applied');
- ok($('#testRussianSettings8').html().match(/^2 минуты/), 'Settings correctly applied');
- // TODO: Test 'минута' and 'минут'
+ test("minutes", function () {
+ ok($("#testLatinSettings8").html().match(/^2 inutes-may/), "Settings correctly applied");
+ ok($("#testRussianSettings8").html().match(/^2 минуты/), "Settings correctly applied");
+ // TODO: Test "минута" and "минут"
});
- test('hour', function () {
- ok($('#testLatinSettings10').html().match(/^about-hay an-hay hour-hay/), 'Settings correctly applied');
- ok($('#testRussianSettings10').html().match(/^час/), 'Settings correctly applied');
+ test("hour", function () {
+ ok($("#testLatinSettings10").html().match(/^about-hay an-hay hour-hay/), "Settings correctly applied");
+ ok($("#testRussianSettings10").html().match(/^час/), "Settings correctly applied");
});
- test('hours', function () {
- ok($('#testLatinSettings12').html().match(/^about-hay 2 hours-hay/), 'Settings correctly applied');
- ok($('#testRussianSettings12').html().match(/^2 часа/), 'Settings correctly applied');
- // TODO: Test 'час' and 'часов'
+ test("hours", function () {
+ ok($("#testLatinSettings12").html().match(/^about-hay 2 hours-hay/), "Settings correctly applied");
+ ok($("#testRussianSettings12").html().match(/^2 часа/), "Settings correctly applied");
+ // TODO: Test "час" and "часов"
});
- test('day', function () {
- ok($('#testLatinSettings15').html().match(/^a-hay ay-day/), 'Settings correctly applied');
- ok($('#testRussianSettings15').html().match(/^день/), 'Settings correctly applied');
+ test("day", function () {
+ ok($("#testLatinSettings15").html().match(/^a-hay ay-day/), "Settings correctly applied");
+ ok($("#testRussianSettings15").html().match(/^день/), "Settings correctly applied");
});
- test('days', function () {
- ok($('#testLatinSettings16').html().match(/^2 ays-day/), 'Settings correctly applied');
- ok($('#testRussianSettings16').html().match(/^2 дня/), 'Settings correctly applied');
- ok($('#testRussianSettings17').html().match(/^29 дней/), 'Settings correctly applied');
- // TODO: Test 'день'
+ test("days", function () {
+ ok($("#testLatinSettings16").html().match(/^2 ays-day/), "Settings correctly applied");
+ ok($("#testRussianSettings16").html().match(/^2 дня/), "Settings correctly applied");
+ ok($("#testRussianSettings17").html().match(/^29 дней/), "Settings correctly applied");
+ // TODO: Test "день"
});
- test('month', function () {
- ok($('#testLatinSettings18').html().match(/^about-hay a-hay onth-may/), 'Settings correctly applied');
- ok($('#testRussianSettings18').html().match(/^месяц/), 'Settings correctly applied');
+ test("month", function () {
+ ok($("#testLatinSettings18").html().match(/^about-hay a-hay onth-may/), "Settings correctly applied");
+ ok($("#testRussianSettings18").html().match(/^месяц/), "Settings correctly applied");
});
- test('months', function () {
- ok($('#testLatinSettings19').html().match(/^6 onths-may/), 'Settings correctly applied');
- ok($('#testRussianSettings19').html().match(/^6 месяцев/), 'Settings correctly applied');
- // TODO: Test 'месяца' and 'месяц'
+ test("months", function () {
+ ok($("#testLatinSettings19").html().match(/^6 onths-may/), "Settings correctly applied");
+ ok($("#testRussianSettings19").html().match(/^6 месяцев/), "Settings correctly applied");
+ // TODO: Test "месяца" and "месяц"
});
- test('year', function () {
- ok($('#testLatinSettings20').html().match(/^about-hay a-hay ear-yay/), 'Settings correctly applied');
- ok($('#testRussianSettings20').html().match(/^год/), 'Settings correctly applied');
+ test("year", function () {
+ ok($("#testLatinSettings20").html().match(/^about-hay a-hay ear-yay/), "Settings correctly applied");
+ ok($("#testRussianSettings20").html().match(/^год/), "Settings correctly applied");
});
- test('years', function () {
- ok($('#testYoungOldSettings1').html().match(/^16 young years/), 'Settings correctly applied');
- ok($('#testYoungOldSettings2').html().match(/^64 old years/), 'Settings correctly applied');
- ok($('#testLatinSettings21').html().match(/^3 years-yay/), 'Settings correctly applied');
- ok($('#testRussianSettings21').html().match(/^3 года/), 'Settings correctly applied');
- // TODO: Test 'год' and 'лет'
+ test("years", function () {
+ ok($("#testYoungOldSettings1").html().match(/^16 young years/), "Settings correctly applied");
+ ok($("#testYoungOldSettings2").html().match(/^64 old years/), "Settings correctly applied");
+ ok($("#testLatinSettings21").html().match(/^3 years-yay/), "Settings correctly applied");
+ ok($("#testRussianSettings21").html().match(/^3 года/), "Settings correctly applied");
+ // TODO: Test "год" and "лет"
});
})(jQuery);
//]]>
View
76 test/test_helpers.js
@@ -0,0 +1,76 @@
+var zeropad = function (num) {
+ return ((num < 10) ? '0' : '') + num;
+};
+var iso8601 = function (date) {
+ return date.getUTCFullYear()
+ + "-" + zeropad(date.getUTCMonth()+1)
+ + "-" + zeropad(date.getUTCDate())
+ + "T" + zeropad(date.getUTCHours())
+ + ":" + zeropad(date.getUTCMinutes())
+ + ":" + zeropad(date.getUTCSeconds()) + "Z";
+};
+
+function prepareDynamicDates() {
+ $('abbr.loaded').attr("title", iso8601(new Date()));
+ $('abbr.modified').attr("title", iso8601(new Date(document.lastModified)));
+}
+
+function loadPigLatin() {
+ jQuery.timeago.settings.strings = {
+ suffixAgo: "ago-hay",
+ suffixFromNow: "omNow-fray",
+ seconds: "ess-lay an-thay a-hay inute-may",
+ minute: "about-hay a-hay inute-may",
+ minutes: "%d inutes-may",
+ hour: "about-hay an-hay hour-hay",
+ hours: "about-hay %d hours-hay",
+ day: "a-hay ay-day",
+ days: "%d ays-day",
+ month: "about-hay a-hay onth-may",
+ months: "%d onths-may",
+ year: "about-hay a-hay ear-yay",
+ years: "%d years-yay"
+ };
+}
+
+function loadRussian() {
+ (function() {
+ function numpf(n, f, s, t) {
+ // f - 1, 21, 31, ...
+ // s - 2-4, 22-24, 32-34 ...
+ // t - 5-20, 25-30, ...
+ var n10 = n % 10;
+ if ( (n10 == 1) && ( (n == 1) || (n > 20) ) ) {
+ return f;
+ } else if ( (n10 > 1) && (n10 < 5) && ( (n > 20) || (n < 10) ) ) {
+ return s;
+ } else {
+ return t;
+ }
+ }
+
+ jQuery.timeago.settings.strings = {
+ prefixAgo: null,
+ prefixFromNow: "через",
+ suffixAgo: "назад",
+ suffixFromNow: null,
+ seconds: "меньше минуты",
+ minute: "минуту",
+ minutes: function(value) { return numpf(value, "%d минута", "%d минуты", "%d минут"); },
+ hour: "час",
+ hours: function(value) { return numpf(value, "%d час", "%d часа", "%d часов"); },
+ day: "день",
+ days: function(value) { return numpf(value, "%d день", "%d дня", "%d дней"); },
+ month: "месяц",
+ months: function(value) { return numpf(value, "%d месяц", "%d месяца", "%d месяцев"); },
+ year: "год",
+ years: function(value) { return numpf(value, "%d год", "%d года", "%d лет"); }
+ };
+ })();
+}
+
+function loadYoungOldYears() {
+ jQuery.extend(jQuery.timeago.settings.strings, {
+ years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; }
+ });
+}

Showing you all comments on commits in this comparison.

@ncr

I hate " ' " too ;)

Something went wrong with that request. Please try again.