3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('yui-later', function(Y) {
10
* Provides a setTimeout/setInterval wrapper. This module is a `core` YUI module, <a href="../classes/YUI.html#method_later">it's documentation is located under the YUI class</a>.
13
* @submodule yui-later
19
* Executes the supplied function in the context of the supplied
20
* object 'when' milliseconds later. Executes the function a
21
* single time unless periodic is set to true.
24
* @param when {int} the number of milliseconds to wait until the fn
26
* @param o the context object.
27
* @param fn {Function|String} the function to execute or the name of
28
* the method in the 'o' object to execute.
29
* @param data [Array] data that is provided to the function. This
30
* accepts either a single item or an array. If an array is provided,
31
* the function is executed with one parameter for each array item.
32
* If you need to pass a single array parameter, it needs to be wrapped
33
* in an array [myarray].
35
* Note: native methods in IE may not have the call and apply methods.
36
* In this case, it will work, but you are limited to four arguments.
38
* @param periodic {boolean} if true, executes continuously at supplied
39
* interval until canceled.
40
* @return {object} a timer object. Call the cancel() method on this
41
* object to stop the timer.
43
Y.later = function(when, o, fn, data, periodic) {
45
data = (!Y.Lang.isUndefined(data)) ? Y.Array(data) : NO_ARGS;
46
o = o || Y.config.win || Y;
48
var cancelled = false,
49
method = (o && Y.Lang.isString(fn)) ? o[fn] : fn,
50
wrapper = function() {
51
// IE 8- may execute a setInterval callback one last time
52
// after clearInterval was called, so in order to preserve
53
// the cancel() === no more runny-run, we have to jump through
57
method(data[0], data[1], data[2], data[3]);
59
method.apply(o, data || NO_ARGS);
63
id = (periodic) ? setInterval(wrapper, when) : setTimeout(wrapper, when);
79
Y.Lang.later = Y.later;
83
}, '3.4.1' ,{requires:['yui-base']});