From 9e16eef401db0ee6013956b92c70eae95246a313 Mon Sep 17 00:00:00 2001 From: Michael Crawford Date: Fri, 9 Aug 2019 11:27:30 -0700 Subject: move debounceresized to own file --- layouts/partials/head.html | 3 ++- static/js/debouncedresize.js | 40 ++++++++++++++++++++++++++++++++++++++++ static/js/grid.js | 41 ----------------------------------------- 3 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 static/js/debouncedresize.js diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 4d7efdd..9da50c7 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -17,6 +17,7 @@ - + + \ No newline at end of file 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 diff --git a/static/js/grid.js b/static/js/grid.js index e22695e..42ae34b 100644 --- a/static/js/grid.js +++ b/static/js/grid.js @@ -1,44 +1,3 @@ -/* -* 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 -}; - // ======================= imagesLoaded Plugin =============================== // https://github.com/desandro/imagesloaded -- cgit v1.2.3