~andreserl/maas/packaging_precise_rebase

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/yui-later/yui-later-debug.js

  • Committer: Andres Rodriguez
  • Date: 2013-03-20 18:12:30 UTC
  • mfrom: (145.2.22 precise.sru)
  • Revision ID: andreserl@ubuntu.com-20130320181230-6l5guc0nhlv2z4p7
Re-base againts latest quantal released branch towards SRU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.5.1 (build 22)
 
3
Copyright 2012 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('yui-later', function(Y) {
 
8
 
 
9
/**
 
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>.
 
11
 *
 
12
 * @module yui
 
13
 * @submodule yui-later
 
14
 */
 
15
 
 
16
var NO_ARGS = [];
 
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
 * @for YUI
 
23
 * @method later
 
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
 
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].
 
34
 *
 
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.
 
37
 *
 
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.
 
42
 */
 
43
Y.later = function(when, o, fn, data, periodic) {
 
44
    when = when || 0;
 
45
    data = (!Y.Lang.isUndefined(data)) ? Y.Array(data) : NO_ARGS;
 
46
    o = o || Y.config.win || Y;
 
47
 
 
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
 
54
            // an extra hoop.
 
55
            if (!cancelled) {
 
56
                if (!method.apply) {
 
57
                    method(data[0], data[1], data[2], data[3]);
 
58
                } else {
 
59
                    method.apply(o, data || NO_ARGS);
 
60
                }
 
61
            }
 
62
        },
 
63
        id = (periodic) ? setInterval(wrapper, when) : setTimeout(wrapper, when);
 
64
 
 
65
    return {
 
66
        id: id,
 
67
        interval: periodic,
 
68
        cancel: function() {
 
69
            cancelled = true;
 
70
            if (this.interval) {
 
71
                clearInterval(id);
 
72
            } else {
 
73
                clearTimeout(id);
 
74
            }
 
75
        }
 
76
    };
 
77
};
 
78
 
 
79
Y.Lang.later = Y.later;
 
80
 
 
81
 
 
82
 
 
83
}, '3.5.1' ,{requires:['yui-base']});