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