Skip to content

Instantly share code, notes, and snippets.

@Nateliason
Created January 14, 2019 20:36
Show Gist options
  • Select an option

  • Save Nateliason/e645376bd12da45249dda5c92ebf5153 to your computer and use it in GitHub Desktop.

Select an option

Save Nateliason/e645376bd12da45249dda5c92ebf5153 to your computer and use it in GitHub Desktop.
Sort book notes
<script>
// Dynamic Filter
$(document).ready(function() {
// Code#001: Set Slug Variables
var slug = function(str) {
var $slug = '';
var trimmed = $.trim(str);
$slug = trimmed.replace(/[^a-z0-9-]/gi, '-').
replace(/-+/g, '-').
replace(/^-|-$/g, '');
return $slug.toLowerCase();
}
// Code#002: Add Classes to Collection List Items
$('#filter-list .w-dyn-item').each(function () {
// The five Category Text Blocks
var category1 = slug($(this).find('.category-inlay:nth-child(1)').text());
var category2 = slug($(this).find('.category-inlay:nth-child(2)').text());
var category3 = slug($(this).find('.category-inlay:nth-child(3)').text());
var category4 = slug($(this).find('.category-inlay:nth-child(4)').text());
var category5 = slug($(this).find('.category-inlay:nth-child(5)').text());
$(this).addClass(category1);
$(this).addClass(category2);
$(this).addClass(category3);
$(this).addClass(category4);
$(this).addClass(category5);
});
// Code#003: Show & Hide Items when Filter Navigation is clicked
$('.filter-item').click(function(){
var navigationCategory = slug($(this).text());
$('#filter-list .w-dyn-item').delay(500).css('display', 'none');
$('.' + navigationCategory).delay(500).css('display', 'block');
$('.filter-item').removeClass('filter-active');
$(this).addClass('filter-active');
$('#category-header').text(navigationCategory.substr(0,1).toUpperCase()+navigationCategory.substr(1));
});
// Code#004: Show All
$('.filter-item:first-child').click(function(){
$('#filter-list .w-dyn-item').delay(500).css('display', 'block');
});
// Code#005: Set Active for Category "All"
$('.filter-item:first-child').addClass('filter-active');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment