From 038b8dcaea5fb1e2b102dd095dfae6c4e630ed54 Mon Sep 17 00:00:00 2001 From: Christoph Burgmer Date: Tue, 25 Jan 2011 16:44:39 +0100 Subject: [PATCH] Allow timeago to be used with jquery-livequery: $('attr.timeago').livequery(function() { $(this).timeago(); }); - Save intervalId to only issue setInterval once - Add selected elements to a global array which we query --- jquery.timeago.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/jquery.timeago.js b/jquery.timeago.js index 9fcf4811..f74936f8 100644 --- a/jquery.timeago.js +++ b/jquery.timeago.js @@ -24,6 +24,8 @@ } }; var $t = $.timeago; + var intervalId = null; + var elements = []; $.extend($.timeago, { settings: { @@ -102,13 +104,19 @@ } }); - $.fn.timeago = function() { + $.fn.timeago = function(clear) { var self = this; - self.each(refresh); + self.each(function (i, element) { + if ($.inArray(element, elements) == -1) + elements.push(element); + }); + $.each(elements, refresh); var $s = $t.settings; if ($s.refreshMillis > 0) { - setInterval(function() { self.each(refresh); }, $s.refreshMillis); + if (intervalId === null) { + intervalId = setInterval(function() { $.each(elements, refresh); }, $s.refreshMillis); + } } return self; };