diff --git a/README.md b/README.md index 221952a..5b0b104 100755 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ A simple and effective way of handling JavaScript internals using jQuery. Versio ## Creating a new timer Timers are created with an easy to remember syntax. - var timer = $.timer(timeout, callback); + var timer = $.timer(timeout, callback, disabled); - `timeout` is the time to set the interval to run at, in milliseconds. - -The callback option can obviously be either a reference to another function, or an anonymous function. +- `callback` can be either a reference to another function, or an anonymous function. +- `disabled` if set to true, the timer is created inactive, needs a .reset() to trigger first. Optional. ## Timer methods In the chance that you need to stop or reset your timer, you can use the following two methods: diff --git a/jquery.timer.js b/jquery.timer.js index 80e41c5..5cbab4a 100755 --- a/jquery.timer.js +++ b/jquery.timer.js @@ -15,7 +15,7 @@ if(!callback) { return false; } - timer = function(interval, callback) { + timer = function(interval, callback, disabled) { // Only used by internal code to call the callback this.internalCallback = function() { callback(self); }; @@ -31,7 +31,11 @@ // Set the interval time again this.interval = interval; - this.id = setInterval(this.internalCallback, this.interval); + + // Set the timer, if enabled + if (!disabled) { + this.id = setInterval(this.internalCallback, this.interval); + } var self = this; };