Open KrunchMuffin opened 9 years ago
So I did some step through debug. It seems it runs through once and does it's thing ok, then it runs through a 2nd time, assuming cause of the listener, and since data-livestamp
no longer exists since it is removed on line 16, it defaults to the current time.
I know it's a bit old, but if anyone has the same problem - here's how i solved this (note: i could not get it to work with unix timestamp):
HTML
<span class="timestamp" data-custom-livestamp="2015-06-09 16:44:37 +0200"></span>
Javascript (after DOM ready)
$("*[data-custom-livestamp]").each(function(value){
var timestamp = this.dataset.customLivestamp;
delete this.dataset.customLivestamp;
$(this).on('change.livestamp', function(event, from, to) {
// custom init code
}).livestamp(new Date(timestamp));
});
Everything works as it should until I implement the listener.
It goes from saying
3 hours ago
to sayinga few seconds ago
on load. Like it's just using the current time instead of the data attribute time provided.