Skip to content

Instantly share code, notes, and snippets.

@funnelback
Created August 20, 2013 11:53
Show Gist options
  • Save funnelback/6280445 to your computer and use it in GitHub Desktop.
Save funnelback/6280445 to your computer and use it in GitHub Desktop.
funnelback-default-faceted-search-client-side-behaviours
// Expandable facet categories and Bootstrap styling.
// Assumes use of bootstrap-search.ftl and non-hierarchical facets
function expandable_facet_categories(defaultFacetCategories) {
$(".facet .panel ul").each(function(){
if ($(this).children(".category").size() > defaultFacetCategories) {
$(this).children(".category").each(function(){
if($(this).index() >= defaultFacetCategories)
$(this).hide();
});
$(this).after("<button type='button' class='btn btn-link btn-xs search-toggle-more-categories' title='Show more categories from this facet'><small><span class='glyphicon glyphicon-chevron-down'></span></small>&nbsp;More&hellip;</button>");
}
});
// Show all categories
$(".search-toggle-more-categories").click(function(){
$(this).siblings("ul").children(".category").show("fast");
$(this).hide();
});
}
function style_selected_facets() {
$(".panel-body ul").each(function() {
if($(this).children(".category").size() == 0) {
// Suppress facet category panel if empty
$(this).parent().hide();
$(this).parent().parent().addClass("panel-primary");
// Hack!
$(".facetLabel a").addClass("btn btn-danger btn-xs pull-right").html("<span class='glyphicon glyphicon-remove'></span>").attr("title","Remove category");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment