mirror of
https://github.com/scratchfoundation/jquery-timeago.git
synced 2024-11-30 03:05:39 -05:00
Added example rails helper
This commit is contained in:
parent
ae48586030
commit
c03193f8c5
1 changed files with 20 additions and 20 deletions
40
index.html
40
index.html
|
@ -48,15 +48,12 @@
|
|||
timestamps (e.g. "4 minutes ago" or "about 1 day ago"). <a href="jquery.timeago.js">Download</a>, view
|
||||
the examples, and enjoy.
|
||||
</p>
|
||||
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<p class="example">
|
||||
This page was last modified <abbr class="modified timeago">sometime before now [browser might not support document.lastModified]</abbr>.
|
||||
</p>
|
||||
|
||||
<p class="example">
|
||||
Ryan was born <abbr class="timeago" title="1978-12-18T17:17:00Z">Dec 18, 1978</abbr>.
|
||||
</p>
|
||||
|
@ -65,35 +62,27 @@
|
|||
<p class="how">
|
||||
First, load <a href="http://jquery.com/">jQuery</a> and the plugin:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
<script src="jquery.min.js" type="text/javascript"></script>
|
||||
<script src="jquery.timeago.js" type="text/javascript"></script></pre>
|
||||
|
||||
<p class="how">
|
||||
Now, let's attach it to your timestamps on DOM ready:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('abbr[class*=timeago]').timeago();
|
||||
});</pre>
|
||||
|
||||
<p class="how">
|
||||
This will turn all <tt>abbr</tt> elements with a class
|
||||
of <tt>timeago</tt> and an <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> timestamp in the title:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
<abbr class="<em>timeago</em>" title="<em>2008-07-17T09:24:17Z</em>">July 17, 2008</abbr></pre>
|
||||
|
||||
<p class="how">
|
||||
into something like this:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
<abbr class="timeago" title="2008-07-17T09:24:17Z"><em><abbr class="timeago" title="2008-07-17T09:24:17Z">time ago</abbr></em></abbr></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>
|
||||
|
@ -106,6 +95,14 @@ jQuery(document).ready(function() {
|
|||
<li>You get to use <a href="http://microformats.org/">microformats</a> like the cool kids.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Where?</h3>
|
||||
<p><a href="jquery.timeago.js">Download the "stable" release</a>.</p>
|
||||
<p>
|
||||
The code is hosted on
|
||||
GitHub: <a href="http://github.com/rmm5t/timeago">http://github.com/rmm5t/timeago</a>.
|
||||
Go on, live on the edge.
|
||||
</p>
|
||||
|
||||
<h3>Who?</h3>
|
||||
<p>
|
||||
Timeago was built by <a href="http://ryan.mcgeary.org">Ryan McGeary</a>
|
||||
|
@ -116,18 +113,21 @@ jQuery(document).ready(function() {
|
|||
in <a href="http://rubyonrails.org">Ruby on Rails</a>.
|
||||
</p>
|
||||
|
||||
<h3>Where?</h3>
|
||||
<p><a href="jquery.timeago.js">Download the "stable" release</a>.</p>
|
||||
<p>
|
||||
The code is hosted on
|
||||
GitHub: <a href="http://github.com/rmm5t/timeago">http://github.com/rmm5t/timeago</a>.
|
||||
Go on, live on the edge.
|
||||
</p>
|
||||
|
||||
<h3>When?</h3>
|
||||
<p class="last">
|
||||
<p>
|
||||
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="last">
|
||||
Need a Rails helper to make those fancy microformat <tt>abbr</tt> tags? Fine, here ya go:
|
||||
</p>
|
||||
<pre>
|
||||
def timeago(time, options = {})
|
||||
options[:class] ||= "timeago"
|
||||
content_tag(:abbr, time.to_s, options.merge(:title => time.getutc.iso8601)) if time
|
||||
end</pre>
|
||||
|
||||
</div>
|
||||
<div id="footer">
|
||||
<div style="float:right;">
|
||||
|
|
Loading…
Reference in a new issue