Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow timeago to be used with jquery-livequery #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cburgmer
Copy link

livequery extends selectors to find elements "even after the page has been loaded and the DOM updated".

This patch extends timeago to be used in conjunction with livequery.

The changes are pretty simple but simply not very pretty. I'd be happy if this idea would go into timeago even in a different form.

$('attr.timeago').livequery(function() {
    $(this).timeago();
});

- Save intervalId to only issue setInterval once
- Add selected elements to a global array which we query
@zackchandler
Copy link

Would like to see this pull request make it in too!

@kaareal
Copy link

kaareal commented May 24, 2011

Yep me too

@mutewinter
Copy link

The included code works great, but has a performance problem. The elements array does not remove elements that are no longer visible on the page. I added the following code to remove elements that aren't visible:

  $.fn.timeago = function() {
    var self = this;
    self.each(refresh);

    // Only keep the elements that aren't hidden
    var visibleElements = [];
    $.each(elements, function(i, e) {
      if (!$(e).is(':hidden')) {
        visibleElements.push(e);
      }
    });
    elements = visibleElements;
    ...

@merdjemak
Copy link

I agree. Timeago being "accurate" to the minute, it would be make sense to have dynamically added elements updated too. It would defeat timeago's purpose if this feature or some similar solution is not implemented.

@diegorv
Copy link

diegorv commented Mar 27, 2012

+1 :/

@shichan
Copy link

shichan commented Mar 30, 2012

+1 on merdjemak's comment. Hope this pull request makes it too

@philfreo
Copy link

philfreo commented Jul 7, 2012

@cburgmer you should remove the clear argument.

Hope this pull request gets accepted... it's a major improvement even if you don't use jquery-livequery

@dgilperez
Copy link

Me too.

@bobartlett
Copy link

+1

@NathanHazout
Copy link

Hello, this was opened a long time ago (no pun intended).
Is there a way today to attach timeago to live elements, without using external plugins?
Is there maybe a different github issue regarding this?

@chalkup
Copy link

chalkup commented Feb 11, 2014

I use timeago with livequery on my site like this:

   $("time.timeago").livequery( ->
        $(this).timeago()
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.