Permalink
Browse files

Add a public cancel() function to stop the periodic call

  • Loading branch information...
1 parent 709ec77 commit 0ebfaec78af001d8c994f44e42f2d02e623a5285 @lmarlow lmarlow committed with Mar 31, 2010
Showing with 8 additions and 2 deletions.
  1. +1 −0 README.markdown
  2. +7 −2 jquery.periodic.js
View
@@ -139,6 +139,7 @@ This plugin also provides some control of it's functionality via the 'this' vari
<tr><td>ajax_complete(xhr, status)</td><td>A function to be called upon completion of a jQuery.ajax call. This function will compare the response of current request to that of the previous request and increment or reset the time period accordingly.</td></tr>
<tr><td>reset()</td><td>Resets the time period to the configured minimum (options.period)</td></tr>
<tr><td>increment()</td><td>Increases the time period as per the settings.</td></tr>
+ <tr><td>cancel()</td><td>Cancels the periodic call.</td></tr>
</table>
## Installation
View
@@ -18,7 +18,8 @@ jQuery.periodic = function (options, callback) {
var settings = jQuery.extend({}, jQuery.periodic.defaults, {
ajax_complete : ajaxComplete,
increment : increment,
- reset : reset
+ reset : reset,
+ cancel : cancel
}, options);
// bookkeeping variables
@@ -34,7 +35,7 @@ jQuery.periodic = function (options, callback) {
// run (or restart if already running) the looping construct
function run() {
// clear/stop existing timer (multiple calls to run() won't result in multiple timers)
- clearTimeout(settings.tid);
+ cancel();
// let it rip!
settings.tid = setTimeout(function() {
// set the context (this) for the callback to the settings object
@@ -77,6 +78,10 @@ jQuery.periodic = function (options, callback) {
// restart with the new timeout
run();
}
+
+ function cancel() {
+ clearTimeout(settings.tid);
+ }
// other functions we might want to implement
function pause() {}

0 comments on commit 0ebfaec

Please sign in to comment.