Created
January 7, 2020 16:21
-
-
Save BaileySimrell/fac4a29df4c10fe55e1922e35cb5e4fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--Enable quick search via Isotope--> | |
<script src="https://npmcdn.com/[email protected]/dist/isotope.pkgd.js"></script> | |
<script> | |
// quick search regex | |
var qsRegex; | |
// init Isotope | |
var $grid = $('.w-dyn-items').isotope({ | |
itemSelector: '.w-dyn-item', | |
layoutMode: 'vertical', | |
filter: function() { | |
return qsRegex ? $(this).text().match( qsRegex ) : true; | |
} | |
}); | |
// use value of search field to filter | |
var $quicksearch = $('.quick-search').keyup( debounce( function() { | |
qsRegex = new RegExp( $quicksearch.val(), 'gi' ); | |
$grid.isotope(); | |
}, 200 ) ); | |
// debounce so filtering doesn't happen every millisecond | |
function debounce( fn, threshold ) { | |
var timeout; | |
return function debounced() { | |
if ( timeout ) { | |
clearTimeout( timeout ); | |
} | |
function delayed() { | |
fn(); | |
timeout = null; | |
} | |
timeout = setTimeout( delayed, threshold || 100 ); | |
} | |
} | |
// focus on search input when bottom search link is clicked | |
$('#bottomsearch').click(function(){ | |
$('#quicksearch').focus(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment