~bjornt/lazr-js/prefetch-yui-3.5

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/yui/yui-throttle-debug.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-01-14 23:32:29 UTC
  • mfrom: (197.1.7 yui-3.3.0)
  • Revision ID: launchpad@pqm.canonical.com-20110114233229-r6i4cazdiiw18o7p
Upgrade to YUI 3.3.0 [r=mars]

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
4
http://developer.yahoo.com/yui/license.html
5
 
version: 3.2.0
6
 
build: 2676
 
5
version: 3.3.0
 
6
build: 3167
7
7
*/
8
8
YUI.add('yui-throttle', function(Y) {
9
9
 
13
13
 * @submodule yui-throttle
14
14
 */
15
15
 
 
16
/*! Based on work by Simon Willison: http://gist.github.com/292562 */
16
17
/**
17
18
 * Throttles a call to a method based on the time between calls.
18
19
 * @method throttle
19
20
 * @for YUI
20
21
 * @param fn {function} The function call to throttle.
21
 
 * @param ms {int} The number of milliseconds to throttle the method call. Can set
22
 
 * globally with Y.config.throttleTime or by call. Passing a -1 will disable the throttle. Defaults to 150
 
22
 * @param ms {int} The number of milliseconds to throttle the method call.
 
23
 * Can set globally with Y.config.throttleTime or by call. Passing a -1 will
 
24
 * disable the throttle. Defaults to 150.
23
25
 * @return {function} Returns a wrapped function that calls fn throttled.
24
26
 * @since 3.1.0
25
27
 */
26
 
 
27
 
/*! Based on work by Simon Willison: http://gist.github.com/292562 */
28
 
 
29
 
var throttle = function(fn, ms) {
 
28
Y.throttle = function(fn, ms) {
30
29
    ms = (ms) ? ms : (Y.config.throttleTime || 150);
31
30
 
32
31
    if (ms === -1) {
35
34
        });
36
35
    }
37
36
 
38
 
    var last = (new Date()).getTime();
 
37
    var last = Y.Lang.now();
39
38
 
40
39
    return (function() {
41
 
        var now = (new Date()).getTime();
 
40
        var now = Y.Lang.now();
42
41
        if (now - last > ms) {
43
42
            last = now;
44
43
            fn.apply(null, arguments);
46
45
    });
47
46
};
48
47
 
49
 
Y.throttle = throttle;
50
 
 
51
 
// We added the redundant definition to later for backwards compatibility.
52
 
// I don't think we need to do the same thing here
53
 
// Y.Lang.throttle = throttle;
54
 
 
55
 
 
56
 
 
57
 
}, '3.2.0' ,{requires:['yui-base']});
 
48
 
 
49
}, '3.3.0' ,{requires:['yui-base']});