-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebounce.js
More file actions
18 lines (18 loc) · 757 Bytes
/
Copy pathdebounce.js
File metadata and controls
18 lines (18 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/** debounce(callback, arguments, delay, object)
* Method to help reduce multifire issues
**/
;(function() {
function debounce(cb, args, delay, obj) { // return function
var tmr;
return function() {
void 0 == obj && (obj = this);
tmr && clearTimeout(tmr);
args = args && 'object' == typeof args ? Array.prototype.slice.call(args) : void 0 != args ? [args] : arguments;
(0 > delay || "number" != typeof delay) && (delay = 250); // 250 milliseconds as a default delay time
tmr = setTimeout(function() { cb.apply(obj, args); }, delay);
}
}
window.hasOwnProperty("debounce") || (window.debounce = debounce);
// Add to jQuery if available
if (window.hasOwnProperty('jQuery') && !jQuery['debounce']) jQuery.debounce = debounce;
})();