yui-later.js revision b39897a381c2203466da5568bfd2862a54a81311
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * Provides a setTimeout/setInterval wrapper
87d6b0a14cce52c4faa4b78fc9878eb553dab0d5Adam Moore * @module yui
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * @submodule yui-later
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore(function() {
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * Executes the supplied function in the context of the supplied
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * object 'when' milliseconds later. Executes the function a
87d6b0a14cce52c4faa4b78fc9878eb553dab0d5Adam Moore * single time unless periodic is set to true.
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * @method later
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * @param when {int} the number of milliseconds to wait until the fn
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * is executed.
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * @param o the context object.
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * @param fn {Function|String} the function to execute or the name of
1b298c6f0ef597aa4ab0b8bcb25430b6c9a87749Adam Moore * the method in the 'o' object to execute.
d4dbc3afb5bb9cfd13490b358dc37bf951104ca7Adam Moore * @param data [Array] data that is provided to the function. This
d4dbc3afb5bb9cfd13490b358dc37bf951104ca7Adam Moore * accepts either a single item or an array. If an array is provided,
9fb523cf517ad4d6a53ae9f461d672cba63835d2Adam Moore * the function is executed with one parameter for each array item.
9fb523cf517ad4d6a53ae9f461d672cba63835d2Adam Moore * If you need to pass a single array parameter, it needs to be wrapped
91ff24e65531ce8bf171340d9384182f8c168af3Adam Moore * in an array [myarray].
91ff24e65531ce8bf171340d9384182f8c168af3Adam Moore * @param periodic {boolean} if true, executes continuously at supplied
91ff24e65531ce8bf171340d9384182f8c168af3Adam Moore * interval until canceled.
91ff24e65531ce8bf171340d9384182f8c168af3Adam Moore * @return {object} a timer object. Call the cancel() method on this
91ff24e65531ce8bf171340d9384182f8c168af3Adam Moore * object to stop the timer.
91ff24e65531ce8bf171340d9384182f8c168af3Adam Moore } : function() {
91ff24e65531ce8bf171340d9384182f8c168af3Adam Moore id = (periodic) ? setInterval(f, when) : setTimeout(f, when);
d4dbc3afb5bb9cfd13490b358dc37bf951104ca7Adam Moore cancel: function() {