Kristo Klausson edited this page Dec 1, 2015 · 10 revisions
Clone this wiki locally

Example 1

This is how I implement timeago in my JavaScript code:

    function activate_timeago()
            var $this = $(this);
            if ($'active')!='yes')
        setTimeout(activate_timeago, 60000);

This iterates through every element with the timeago class and checks if it has timeago activated. If it doesn't, it activates it. This check ensures that it is not activated multiple times on the same element, which can slow things down.



Switch between time ago and back

Timeago is super neat when it comes to reading text, but sometimes you need to copy text block to an email and then non-relative time is more appropriate.

$('abbr.timeago').timeago().click(function() {
  var $el = $(this);
  // on click toggle between views
  var old = $el.attr('title');
  $el.attr('title', $el.text());

See ticket #250 for more details