X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/0494b8d9b9bb03ab6c22b34dae81261e3cd7e3e6:/src/ext-core/src/util/DelayedTask.js..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/src/core/src/util/DelayedTask.js diff --git a/src/ext-core/src/util/DelayedTask.js b/src/core/src/util/DelayedTask.js similarity index 57% rename from src/ext-core/src/util/DelayedTask.js rename to src/core/src/util/DelayedTask.js index 898c7ced..41a1efbb 100644 --- a/src/ext-core/src/util/DelayedTask.js +++ b/src/core/src/util/DelayedTask.js @@ -1,47 +1,48 @@ -/*! - * Ext JS Library 3.3.1 - * Copyright(c) 2006-2010 Sencha Inc. - * licensing@sencha.com - * http://www.sencha.com/license - */ /** * @class Ext.util.DelayedTask - *

The DelayedTask class provides a convenient way to "buffer" the execution of a method, + * + * The DelayedTask class provides a convenient way to "buffer" the execution of a method, * performing setTimeout where a new timeout cancels the old timeout. When called, the * task will wait the specified time period before executing. If durng that time period, * the task is called again, the original call will be cancelled. This continues so that - * the function is only called a single time for each iteration.

- *

This method is especially useful for things like detecting whether a user has finished + * the function is only called a single time for each iteration. + * + * This method is especially useful for things like detecting whether a user has finished * typing in a text field. An example would be performing validation on a keypress. You can * use this class to buffer the keypress events for a certain number of milliseconds, and - * perform only if they stop for that amount of time. Usage:


-var task = new Ext.util.DelayedTask(function(){
-    alert(Ext.getDom('myInputField').value.length);
-});
-// Wait 500ms before calling our function. If the user presses another key 
-// during that 500ms, it will be cancelled and we'll wait another 500ms.
-Ext.get('myInputField').on('keypress', function(){
-    task.{@link #delay}(500); 
-});
- * 
- *

Note that we are using a DelayedTask here to illustrate a point. The configuration - * option buffer for {@link Ext.util.Observable#addListener addListener/on} will - * also setup a delayed task for you to buffer events.

+ * perform only if they stop for that amount of time. + * + * ## Usage + * + * var task = new Ext.util.DelayedTask(function(){ + * alert(Ext.getDom('myInputField').value.length); + * }); + * + * // Wait 500ms before calling our function. If the user presses another key + * // during that 500ms, it will be cancelled and we'll wait another 500ms. + * Ext.get('myInputField').on('keypress', function(){ + * task.{@link #delay}(500); + * }); + * + * Note that we are using a DelayedTask here to illustrate a point. The configuration + * option `buffer` for {@link Ext.util.Observable#addListener addListener/on} will + * also setup a delayed task for you to buffer events. + * * @constructor The parameters to this constructor serve as defaults and are not required. * @param {Function} fn (optional) The default function to call. * @param {Object} scope The default scope (The this reference) in which the * function is called. If not specified, this will refer to the browser window. * @param {Array} args (optional) The default Array of arguments. */ -Ext.util.DelayedTask = function(fn, scope, args){ +Ext.util.DelayedTask = function(fn, scope, args) { var me = this, - id, - call = function(){ - clearInterval(id); - id = null; - fn.apply(scope, args || []); - }; - + id, + call = function() { + clearInterval(id); + id = null; + fn.apply(scope, args || []); + }; + /** * Cancels any pending timeout and queues a new one * @param {Number} delay The milliseconds to delay @@ -50,7 +51,7 @@ Ext.util.DelayedTask = function(fn, scope, args){ * is specified, this will refer to the browser window. * @param {Array} newArgs (optional) Overrides args passed to constructor */ - me.delay = function(delay, newFn, newScope, newArgs){ + this.delay = function(delay, newFn, newScope, newArgs) { me.cancel(); fn = newFn || fn; scope = newScope || scope; @@ -61,8 +62,8 @@ Ext.util.DelayedTask = function(fn, scope, args){ /** * Cancel the last queued timeout */ - me.cancel = function(){ - if(id){ + this.cancel = function(){ + if (id) { clearInterval(id); id = null; }