<nav class="facets" id="facets" aria-labelledby="facets-title">
<button class="facets__title" id="facets-title">Filter results</button>
<div class="facets__facets">
</div>
</nav>
<script id="facets-group-template" type="text/template"></script>
<script id="facets-item-template" type="text/template"></script>
This component will show the facets of search results
h1
and h2
elements, every heading (h1 - h6
) will work so choose your own heading according the structure of the page.To start using this component, some JavaScript is needed to initialize it.
Underneath a jQuery example on how to initialize the facets.
The script needs to be placed in the Additional component(s) script
section as documented in How to use.
Look at the example to see how the data needs to be formatted that you can feed the facets script:
[
{
title: 'Document type',
facets: [
{ title: 'PDF document (10)', url: '#pdf', active: true },
{ title: 'Webpage (5)', callback: callbackFunction}
]
},
{
title: 'Date',
facets: [
{ title: 'Last week (7)' },
{ title: 'This week (3)' },
{ title: 'Today (5)' }
]
}
]
<script>
var facets = new nijmegen.Facets();
function facetClickHandler(event, $facetItem) {
if ($facetItem.hasClass('active')) {
$('#facets .facets__item').removeClass('active');
event.preventDefault();
return;
}
$('#facets .facets__item').removeClass('active');
$facetItem.addClass('active');
event.preventDefault();
}
$(document).ready(function () {
var facetData = [
{
title: 'Document type',
facets: [
{ title: 'Webpagina (5)' },
{ title: 'PDF document (10)' }
]
},
{
title: 'Datum',
facets: [
{ title: 'Vandaag (5)' },
{ title: 'Deze week (3)' },
{ title: 'Afgelopen week (7)' }
]
}
];
facets.init('#facets', facetClickHandler);
facets.show(facetData);
});
</script>
Normally the facets are only collapsed in the mobile view. It is also possible to configure the facets to also collapse in the desktop view.
The third argument of the facets init function (allowCollapseOnDesktop
) defaults to false
but can be set to true
to collapse the facets on desktop.
<script>
facets.init('#facets', facetClickHandler, true);
</script>