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-throttle', function (Y, NAME) {
11 Throttles a call to a method based on the time between calls. This method is attached
12 to the `Y` object and is <a href="../classes/YUI.html#method_throttle">documented there</a>.
14 var fn = Y.throttle(function() {
18 for (i; i< 35000; i++) {
25 @submodule yui-throttle
28 /*! Based on work by Simon Willison: http://gist.github.com/292562 */
30 * Throttles a call to a method based on the time between calls.
33 * @param fn {function} The function call to throttle.
34 * @param ms {Number} The number of milliseconds to throttle the method call.
35 * Can set globally with Y.config.throttleTime or by call. Passing a -1 will
36 * disable the throttle. Defaults to 150.
37 * @return {function} Returns a wrapped function that calls fn throttled.
40 Y.throttle = function(fn, ms) {
41 ms = (ms) ? ms : (Y.config.throttleTime || 150);
45 fn.apply(this, arguments);
49 var last = Y.Lang.now();
52 var now = Y.Lang.now();
53 if (now - last > ms) {
55 fn.apply(this, arguments);
61 }, '3.13.0', {"requires": ["yui-base"]});