Jquery.clockwinder is a project mainly written in JavaScript, it's free.
Automatically update relative times with this simple jQuery plugin.
Clockwinder is a simple jQuery plugin for displaying relative times in web applications. Using Clockwinder, you can easily provide relative times (e.g. 10 minutes ago
) purely using Javascript. Essentially, Clockwinder encapsulates the functionality of Rails's time_ago_in_words in Javascript with convenience methods for automatically keeping things up to date. The actual time_ago_in_words
Javascript code came from this blog post.
Simply add the Clockwinder javascript to your project somewhere and include it in your page (after jQuery):
<script src="/javascripts/jquery.clockwinder.js" type="text/javascript" charset="utf-8"></script>
Then call it on whatever elements you want to be kept up to date. By default, it will take the contents of the datetime
attribute on the specified elements and use that as a basis for the relative time.
// Apply Clockwinder to all <time> tags with a 'relative' class
$('time.relative').clockwinder();
Now load the page and watch the times update themselves!
Call via $(element).clockwinder({ /* Options here... */})
'ago'
.this
scoped to the element that's being updated and arguments of newTime
(the newest time string calculated) and options
(the options that were passed to Clockwinder).