Sha256: 59f18e2e95f29ff3d550720621a008a973f1f163bf0aae3d539c4b8387259805

Contents?: true

Size: 1.59 KB

Versions: 13

Compression:

Stored size: 1.59 KB

Contents

(function(window) {
    var $ = window.jQuery || window.me || (window.me = {}),
        throttle = function(fn, timeout, callback, delayed, trailing, debounce) {
            timeout || (timeout = 100);
            var timer = false,
                lastCall = false,
                hasCallback = (typeof callback === "function"),
                startTimer = function(wrapper, args) {
                    timer = setTimeout(function(){
                        timer = false;
                        if (delayed || trailing) {
                            fn.apply(wrapper, args);
                            if (trailing) { lastCall = +new Date(); }
                        }
                        if (hasCallback) { callback.apply(wrapper, args); }
                    }, timeout);
                },
                wrapper = function(){
                    if (timer && !debounce) { return; }
                    if (!timer && !delayed) {
                        if (!trailing || (+new Date()-lastCall) > timeout) {
                            fn.apply(this, arguments);
                            if (trailing) { lastCall = +new Date(); }
                        }
                    }
                    if (debounce || !trailing) { clearTimeout(timer); }
                    startTimer(this, arguments);
                }
            if ($.guid) { wrapper.guid = fn.guid = fn.guid || $.guid++; }
            return wrapper;
        };
    $.throttle = throttle;
    $.debounce = function(fn, timeout, callback, delayed, trailing) {
        return throttle(fn, timeout, callback, delayed, trailing, true);
    };
})(this);

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
listings-0.1.15 app/assets/javascripts/jquery-throttle.js
listings-0.1.14 app/assets/javascripts/jquery-throttle.js
listings-0.1.13 app/assets/javascripts/jquery-throttle.js
listings-0.1.12 app/assets/javascripts/jquery-throttle.js
listings-0.1.11 app/assets/javascripts/jquery-throttle.js
listings-0.1.10 app/assets/javascripts/jquery-throttle.js
listings-0.1.8 app/assets/javascripts/jquery-throttle.js
listings-0.1.7 app/assets/javascripts/jquery-throttle.js
listings-0.1.6 app/assets/javascripts/jquery-throttle.js
listings-0.1.5 app/assets/javascripts/jquery-throttle.js
listings-0.1.4 app/assets/javascripts/jquery-throttle.js
listings-0.1.0 app/assets/javascripts/jquery-throttle.js
listings-0.0.3 app/assets/javascripts/jquery-throttle.js