From d819b57c82f12626b031ba0888c7359d2aa228af Mon Sep 17 00:00:00 2001 From: gaboom Date: Mon, 18 Mar 2013 23:01:23 +0100 Subject: [PATCH 1/2] Update jquery.timer.js Add option for disabled timers. --- jquery.timer.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; }; From c26b3d9fbafeab491e047fc85d689f80e28a3c2f Mon Sep 17 00:00:00 2001 From: gaboom Date: Mon, 18 Mar 2013 23:03:43 +0100 Subject: [PATCH 2/2] Update README.md Update README.md with disabled option. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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: