From 3b895714a66cc3ad7c3374e75c5d1224c8dc3e87 Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 25 Jun 2013 14:37:26 -0400 Subject: [PATCH] Add 'dispose' action - use with elements about to be removed from the DOM or that otherwise no longer require updating - only clears interval; leaves node as-is - usage: $('.timeago').timeago('dispose'); --- jquery.timeago.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jquery.timeago.js b/jquery.timeago.js index 4d58026..018c474 100644 --- a/jquery.timeago.js +++ b/jquery.timeago.js @@ -128,7 +128,7 @@ refresh_el(); var $s = $t.settings; if ($s.refreshMillis > 0) { - setInterval(refresh_el, $s.refreshMillis); + this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis); } }, update: function(time){ @@ -138,6 +138,12 @@ updateFromDOM: function(){ $(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) }); refresh.apply(this); + }, + dispose: function () { + if (this._timeagoInterval) { + window.clearInterval(this._timeagoInterval); + this._timeagoInterval = null; + } } };