summaryrefslogtreecommitdiff
path: root/html/assets/js/utils/debounce.js
blob: f81d9a5e2fb61bfb2ab4ca0c6120ec5e0d1366a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
define('debounce', function () {
    return function (func, wait, immediate) {
        var timeout;
        return function () {
            var context = this, args = arguments;
            var later = function () {
                timeout = null;
                if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
        };
    };
});