Skip to content

Instantly share code, notes, and snippets.

@BaileySimrell
Created January 7, 2020 16:21
Show Gist options
  • Save BaileySimrell/fac4a29df4c10fe55e1922e35cb5e4fb to your computer and use it in GitHub Desktop.
Save BaileySimrell/fac4a29df4c10fe55e1922e35cb5e4fb to your computer and use it in GitHub Desktop.
<!--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