Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions jquery.timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); };

Expand All @@ -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;
};
Expand Down