Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continues to Count when Element is gone #8

Open
Nvenom opened this issue Dec 13, 2012 · 1 comment
Open

Continues to Count when Element is gone #8

Nvenom opened this issue Dec 13, 2012 · 1 comment

Comments

@Nvenom
Copy link

Nvenom commented Dec 13, 2012

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));
            }
        }
@greggreenhaw
Copy link

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');
                };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants