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');
This commit is contained in:
Dave 2013-06-25 14:37:26 -04:00
parent 49aeb6bf07
commit 3b895714a6

View file

@ -128,7 +128,7 @@
refresh_el(); refresh_el();
var $s = $t.settings; var $s = $t.settings;
if ($s.refreshMillis > 0) { if ($s.refreshMillis > 0) {
setInterval(refresh_el, $s.refreshMillis); this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
} }
}, },
update: function(time){ update: function(time){
@ -138,6 +138,12 @@
updateFromDOM: function(){ updateFromDOM: function(){
$(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) }); $(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
refresh.apply(this); refresh.apply(this);
},
dispose: function () {
if (this._timeagoInterval) {
window.clearInterval(this._timeagoInterval);
this._timeagoInterval = null;
}
} }
}; };