1/** 2 * Debounce and throttle function's decorator plugin 1.0.5 3 * 4 * Copyright (c) 2009 Filatov Dmitry ([email protected]) 5 * Dual licensed under the MIT and GPL licenses: 6 * http://www.opensource.org/licenses/mit-license.php 7 * http://www.gnu.org/licenses/gpl.html 8 * 9 */ 10 11(function($) { 12 13$.extend({ 14 15 debounce : function(fn, timeout, invokeAsap, ctx) { 16 17 if(arguments.length == 3 && typeof invokeAsap != 'boolean') { 18 ctx = invokeAsap; 19 invokeAsap = false; 20 } 21 22 var timer; 23 24 return function() { 25 26 var args = arguments; 27 ctx = ctx || this; 28 29 invokeAsap && !timer && fn.apply(ctx, args); 30 31 clearTimeout(timer); 32 33 timer = setTimeout(function() { 34 !invokeAsap && fn.apply(ctx, args); 35 timer = null; 36 }, timeout); 37 38 }; 39 40 }, 41 42 throttle : function(fn, timeout, ctx) { 43 44 var timer, args, needInvoke; 45 46 return function() { 47 48 args = arguments; 49 needInvoke = true; 50 ctx = ctx || this; 51 52 if(!timer) { 53 (function() { 54 if(needInvoke) { 55 fn.apply(ctx, args); 56 needInvoke = false; 57 timer = setTimeout(arguments.callee, timeout); 58 } 59 else { 60 timer = null; 61 } 62 })(); 63 } 64 65 }; 66 67 } 68 69}); 70 71})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.