Skip to content

Commit 3b89571

Browse files
author
Dave
committed
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');
1 parent 49aeb6b commit 3b89571

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

jquery.timeago.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
refresh_el();
129129
var $s = $t.settings;
130130
if ($s.refreshMillis > 0) {
131-
setInterval(refresh_el, $s.refreshMillis);
131+
this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
132132
}
133133
},
134134
update: function(time){
@@ -138,6 +138,12 @@
138138
updateFromDOM: function(){
139139
$(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
140140
refresh.apply(this);
141+
},
142+
dispose: function () {
143+
if (this._timeagoInterval) {
144+
window.clearInterval(this._timeagoInterval);
145+
this._timeagoInterval = null;
146+
}
141147
}
142148
};
143149

0 commit comments

Comments
 (0)