You are viewing version 3 of the library, the latest version is

Facets

<section class="facets" id="facets" role="navigation">
    <h1 class="facets__title">Filter results</h1>
    <div class="facets__facets">
    </div>
</section>

<script id="facets-group-template" type="text/template">
    <div class="facets__group">
        <h2 class="facets__group-title"></h2>
        <ul class="facets__list">
        </ul>
    </div>
</script>

<script id="facets-item-template" type="text/template">
    <li class="facets__item">
        <a class="facets__link" href=""></a>
    </li>
</script>

Facets

This component will show the facets of search results

Note

  • In the example the facet is rendered in a column. You should do this yourself when implementing the facets.
  • The titles in this component are rendered via h1 and h2 elements, every heading (h1 - h6) will work so choose your own heading according the structure of the page.

Using

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)' }
        ]
    }
]

Example on how to implement:

<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>