mattbradley / livestampjs

A simple, unobtrusive jQuery plugin that provides auto-updating timeago text to your timestamped HTML elements using Moment.js.
http://mattbradley.github.com/livestampjs
MIT License
409 stars 70 forks source link

long waiting time #21

Closed Electrofenster closed 9 years ago

Electrofenster commented 10 years ago

Hello, I parse every 5 seconds an li via

setInterval(function () {
    $.get('lib/includes/ayax_load_notifications.php', function( data ) {
        $('.notification_list').html(data);
    });
}, 5000)

but the string "5 minutes ago" loads 3-4secs later than the li :(

Any solutions?

szelga commented 10 years ago

in such cases i insert the appropriate string into a span element. i use frontend template rendering, so it's like this (in jade template language):

span(data-livestamp=timeStamp.unix())
  | #{timeStamp.fromNow()}

(assuming that timeStamp is a moment object).

AndersDJohnson commented 10 years ago

@Electrofenster

Hmm, the update interval defaults to 1 second, so I'm surprised you're seeing 3-4 seconds.

You can manually trigger livestamp to update on demand for the new elements. If you are using the default data-livestamp attributes, you can simply put a call to $.livestamp.update() after updating DOM with .html(data) in your $.get callback.

Otherwise you can do it manually after selecting your new elements using $(...).livestamp().

See example: http://plnkr.co/edit/bFW8wYTKSo99W3xjmf8x

Let me know if this solves your issue so we can close.