]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/yui/yui-later.js
Release 6.2.0beta4
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / yui / yui-later.js
1 /*
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
5 version: 3.0.0
6 build: 1549
7 */
8 YUI.add('yui-later', function(Y) {
9
10 /**
11  * Provides a setTimeout/setInterval wrapper
12  * @module yui
13  * @submodule yui-later
14  */
15 (function() {
16     var L = Y.Lang,
17
18     /**
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.
22      * @method later
23      * @for YUI
24      * @param when {int} the number of milliseconds to wait until the fn 
25      * is executed.
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 accepts
30      * either a single item or an array.  If an array is provided, the
31      * function is executed with one parameter for each array item.  If
32      * you need to pass a single array parameter, it needs to be wrapped in
33      * an array [myarray].
34      * @param periodic {boolean} if true, executes continuously at supplied 
35      * interval until canceled.
36      * @return {object} a timer object. Call the cancel() method on this object to 
37      * stop the timer.
38      */
39     later = function(when, o, fn, data, periodic) {
40         when = when || 0; 
41         o = o || {};
42         var m=fn, d=Y.Array(data), f, r;
43
44         if (L.isString(fn)) {
45             m = o[fn];
46         }
47
48         if (!m) {
49         }
50
51         f = function() {
52             m.apply(o, d);
53         };
54
55         r = (periodic) ? setInterval(f, when) : setTimeout(f, when);
56
57         return {
58             id: r,
59             interval: periodic,
60             cancel: function() {
61                 if (this.interval) {
62                     clearInterval(r);
63                 } else {
64                     clearTimeout(r);
65                 }
66             }
67         };
68     };
69
70     Y.later = later;
71     L.later = later;
72
73 })();
74
75
76 }, '3.0.0' ,{requires:['yui-base']});