diff --git a/index.html b/index.html index 8971bda..7ce2bab 100644 --- a/index.html +++ b/index.html @@ -7,22 +7,9 @@ timeago jQuery plugin - + @@ -38,9 +25,10 @@ p.how, p.last { margin: 0; } ul { margin: 0 24px 24px; } li { line-height: 24px; } - pre { background-color: #333; color: #fff; margin: 12px 0; font-size: 12px; } + pre { background-color: #333; color: #fff; margin: 12px 0; font-size: 12px; padding: 0 6px; } pre em { font-style: normal; background-color: #554; } pre, tt { font-family: monaco,"courier new",mono; } + abbr { border-bottom: 1px dotted #333; } tt { font-size: 14px; } a { color: #06e; padding: 1px; } a:hover { background-color: #06c; color: #fff; text-decoration: none; } @@ -79,17 +67,17 @@

-  <script src="jquery.min.js" type="text/javascript"></script>
-  <script src="jquery.timeago.js" type="text/javascript"></script>
+<script src="jquery.min.js" type="text/javascript"></script> +<script src="jquery.timeago.js" type="text/javascript"></script>

Now, let's attach it to your timestamps on DOM ready:

-  jQuery(document).ready(function() {
-    jQuery('abbr[class*=timeago]').timeago();
-  });
+jQuery(document).ready(function() { + jQuery('abbr[class*=timeago]').timeago(); +});

This will turn all abbr elements with a class @@ -97,14 +85,14 @@

-  <abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
+<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>

into something like this:

-  <abbr class="timeago" title="2008-07-17T09:24:17Z">6 hours ago</abbr>
+<abbr class="timeago" title="2008-07-17T09:24:17Z">6 hours ago</abbr>

As time passes, the timestamps will automatically update. diff --git a/test.html b/test.html index b4464d7..e5cb08e 100644 --- a/test.html +++ b/test.html @@ -6,6 +6,7 @@ Timeago jQuery Plugin Tests + +

Functional tests:

+

Short term

+ You opened this page sometime before now.
+ This page was last modified sometime before now.
+

Long term

Jett was born bleh [from Z]
Jett was born bleh [from -0500]
@@ -32,6 +46,14 @@ Ryan was born bleh [from Z]
Ryan was born bleh [from -0500]
+

Other formats

+ Date only: (you shouldn't see this).
+ +

Errors

+ Bad (letters): (this should be displayed).
+ Bad (numbers): (this should be displayed).
+ Bad (missing): (this should be displayed).
+

Parsing unit tests:

Ryan was born...
[from Z]
@@ -40,5 +62,23 @@ [from -0500]
[from +09:00]
[from +0900]
+ +

Wording unit tests:

+ [-1 sec]
+ [0 sec]
+ [30 sec]
+ [45 sec]
+ [90 sec]
+ [120 sec]
+ [45 min]
+ [89 min]
+ [90 min]
+ [120 min]
+ [1380 min]
+ [696 hours]
+ [30 days]
+ [190 days]
+ [366 days]
+ [1095 days]
diff --git a/test.js b/test.js new file mode 100644 index 0000000..508b7ae --- /dev/null +++ b/test.js @@ -0,0 +1,16 @@ +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"; +}; + +jQuery(document).ready(function($) { + $('abbr[class*=loaded]').attr("title", iso8601(new Date())); + $('abbr[class*=modified]').attr("title", iso8601(new Date(document.lastModified))); +});