2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.util.DelayedTask
\r
11 * Provides a convenient method of performing setTimeout where a new
\r
12 * timeout cancels the old timeout. An example would be performing validation on a keypress.
\r
13 * You can use this class to buffer
\r
14 * the keypress events for a certain number of milliseconds, and perform only if they stop
\r
15 * for that amount of time.
\r
16 * @constructor The parameters to this constructor serve as defaults and are not required.
\r
17 * @param {Function} fn (optional) The default function to timeout
\r
18 * @param {Object} scope (optional) The default scope of that timeout
\r
19 * @param {Array} args (optional) The default Array of arguments
\r
21 Ext.util.DelayedTask = function(fn, scope, args){
\r
22 var id = null, d, t;
\r
24 var call = function(){
\r
25 var now = new Date().getTime();
\r
29 fn.apply(scope, args || []);
\r
33 * Cancels any pending timeout and queues a new one
\r
34 * @param {Number} delay The milliseconds to delay
\r
35 * @param {Function} newFn (optional) Overrides function passed to constructor
\r
36 * @param {Object} newScope (optional) Overrides scope passed to constructor
\r
37 * @param {Array} newArgs (optional) Overrides args passed to constructor
\r
39 this.delay = function(delay, newFn, newScope, newArgs){
\r
40 if(id && delay != d){
\r
44 t = new Date().getTime();
\r
46 scope = newScope || scope;
\r
47 args = newArgs || args;
\r
49 id = setInterval(call, d);
\r
54 * Cancel the last queued timeout
\r
56 this.cancel = function(){
\r