Only bind timeago plugin to an element once#26
Only bind timeago plugin to an element once#26stevenharman wants to merge 2 commits intormm5t:masterfrom
Conversation
This change will filter out any elements that have already been bound to the timeago plugin so they are not included in multiple setInterval closures. NOTE: I also had to bump the version of jQuery used as 1.4.2 has a bug where it wouldn't call the .each(callback). Perhaps this is due to changes to the .filter method? Moving to 1.4.1 or 1.4.4 is also acceptable.
|
I didn't realize the new Pull Request system auto-creates a new issue. I've closed the original Issue #25 and copied it's text here. Sorry for the confusion |
|
+1 for fixing this. Right now the naive way to use this plugin with dynamic content is to just call #30 is related but the plugin should work better without using a jquery plugin like livequery |
|
Wouldn't the solution be to use a global array that stores the IDs resulting from e.g. if(id_array.length > 1) {
for(var i=0; i < id_array.length-1; i++) {
clearInterval(id_array[i]);
id_array.splice(i,1);
}
}
id_array.push(setInterval([...])); |
Currently, every time an element is passed into the $.fn.timeago() method that element is included in the setInterval, regardless of whether or not it has already been included in a previous interval.
We have found this problematic as we use a event to trigger binding of the timeago plugin, like so (within a Sammy.js app):
app.bind('widgetsRendered', function(e) {
$('.timestamp').timeago();
});
It would be ideal if only elements that were not already bound to timeago were included in the setInterval.