3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.util.DelayedTask"></div>/**
9 * @class Ext.util.DelayedTask
10 * <p> The DelayedTask class provides a convenient way to "buffer" the execution of a method,
11 * performing setTimeout where a new timeout cancels the old timeout. When called, the
12 * task will wait the specified time period before executing. If durng that time period,
13 * the task is called again, the original call will be cancelled. This continues so that
14 * the function is only called a single time for each iteration.</p>
15 * <p>This method is especially useful for things like detecting whether a user has finished
16 * typing in a text field. An example would be performing validation on a keypress. You can
17 * use this class to buffer the keypress events for a certain number of milliseconds, and
18 * perform only if they stop for that amount of time. Usage:</p><pre><code>
19 var task = new Ext.util.DelayedTask(function(){
20 alert(Ext.getDom('myInputField').value.length);
22 // Wait 500ms before calling our function. If the user presses another key
23 // during that 500ms, it will be cancelled and we'll wait another 500ms.
24 Ext.get('myInputField').on('keypress', function(){
25 task.{@link #delay}(500);
28 * <p>Note that we are using a DelayedTask here to illustrate a point. The configuration
29 * option <tt>buffer</tt> for {@link Ext.util.Observable#addListener addListener/on} will
30 * also setup a delayed task for you to buffer events.</p>
31 * @constructor The parameters to this constructor serve as defaults and are not required.
32 * @param {Function} fn (optional) The default function to timeout
33 * @param {Object} scope (optional) The default scope of that timeout
34 * @param {Array} args (optional) The default Array of arguments
36 Ext.util.DelayedTask = function(fn, scope, args){
42 fn.apply(scope, args || []);
45 <div id="method-Ext.util.DelayedTask-delay"></div>/**
46 * Cancels any pending timeout and queues a new one
47 * @param {Number} delay The milliseconds to delay
48 * @param {Function} newFn (optional) Overrides function passed to constructor
49 * @param {Object} newScope (optional) Overrides scope passed to constructor
50 * @param {Array} newArgs (optional) Overrides args passed to constructor
52 me.delay = function(delay, newFn, newScope, newArgs){
55 scope = newScope || scope;
56 args = newArgs || args;
57 id = setInterval(call, delay);
60 <div id="method-Ext.util.DelayedTask-cancel"></div>/**
61 * Cancel the last queued timeout
63 me.cancel = function(){