Skip to content

Allow timeago to be used with jquery-livequery#30

Open
cburgmer wants to merge 1 commit intormm5t:masterfrom
nwebs:master
Open

Allow timeago to be used with jquery-livequery#30
cburgmer wants to merge 1 commit intormm5t:masterfrom
nwebs:master

Conversation

@cburgmer
Copy link
Copy Markdown

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
Copy Markdown

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

@kaareal
Copy link
Copy Markdown

kaareal commented May 24, 2011

Yep me too

@mutewinter
Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

diegorv commented Mar 27, 2012

+1 :/

@shichan
Copy link
Copy Markdown

shichan commented Mar 30, 2012

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

@philfreo
Copy link
Copy Markdown

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
Copy Markdown

Me too.

@bobartlett
Copy link
Copy Markdown

+1

@NathanHazout
Copy link
Copy Markdown

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
Copy Markdown

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.