Continues to Count when Element is gone
Nvenom opened this issue · comments
Nvenom commented
I use this to count a users time spent with a dialog open, and i was feeling a bit lazy to bind a destroy function to all the dialog close functions, so naturally i added a little quick fix. im no expert so im not sure if this is okay or if it will continue to run "render"
Changed
render: function() {
var $this = $(this),
data = $this.data('stopwatch');
$this.html(data.formatter(data.elapsed, data));
}
To This
render: function() {
var $this = $(this),
data = $this.data('stopwatch');
if(data){
$this.html(data.formatter(data.elapsed, data));
}
}
Greg Greenhaw commented
You want to clear the interval instead
data.tick_function = function() {
var millis = data.incrementer();
if(!$this.data('stopwatch')) {
clearInterval(data.timerID);
return;
}
data.elapsed = millis;
data.target.trigger('tick.stopwatch', [millis]);
data.target.stopwatch('render');
};