diff options
Diffstat (limited to 'static/js/debouncedresize.js')
-rw-r--r-- | static/js/debouncedresize.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/static/js/debouncedresize.js b/static/js/debouncedresize.js new file mode 100644 index 0000000..9f2c276 --- /dev/null +++ b/static/js/debouncedresize.js @@ -0,0 +1,40 @@ +/* +* debouncedresize: special jQuery event that happens once after a window resize +* +* latest version and complete README available on Github: +* https://github.com/louisremi/jquery-smartresize/blob/master/jquery.debouncedresize.js +* +* Copyright 2011 @louis_remi +* Licensed under the MIT license. +*/ +var $event = $.event, + $special, + resizeTimeout; + +$special = $event.special.debouncedresize = { + setup: function() { + $( this ).on( "resize", $special.handler ); + }, + teardown: function() { + $( this ).off( "resize", $special.handler ); + }, + handler: function( event, execAsap ) { + // Save the context + var context = this, + args = arguments, + dispatch = function() { + // set correct event type + event.type = "debouncedresize"; + $event.dispatch.apply( context, args ); + }; + + if ( resizeTimeout ) { + clearTimeout( resizeTimeout ); + } + + execAsap ? + dispatch() : + resizeTimeout = setTimeout( dispatch, $special.threshold ); + }, + threshold: 250 +};
\ No newline at end of file |