Interceptors

Interceptors

Interceptors are functions that modify the data before it is shown.

The interceptor function should return a resolved promise with the modified data. To set it to a component, set this component so that it overwrites its basic function to return the data without modification.

Contents interceptor

Use this interceptor to modify the contents before they are printed. The setting is setContentsDataInterceptor.

Example
To add an icon in each content:

    var results = sdk.component('results', '#results');
    results.setContentsDataInterceptor(
        function (contents){
            for (var i = 0; i < contents.length; i++) {
                contents[i]['title'] = '<span class="title__icon"> > </span>'+contents[i]['title'];
            }
            return Promise.resolve(contents);
        }
    );
Categories interceptor

Use this interceptor to modify the categories before they are printed. The setting is setCategoriesDataInterceptor.

Example
To add an icon in each category:

    var categories = sdk.component('categories', '#categories');
    categories.setCategoriesDataInterceptor(
        function (categories){
            for (var i = 0; i < categories.length; i++) {
                categories[i]['name'] = '<span class="title__icon"> > </span>'+categories[i]['name'];
            }
            return Promise.resolve(categories);
        }
    );
Autocompleter interceptor

Use this interceptor to modify the autocompleter data before it is printed. The setting is setAutocompleterDataInterceptor.

Example
To add a '>' sign in each autocompleter object:

    var autocompleter = sdk.component('autocompleter', '#autocompleter');
    autocompleter.setAutocompleterDataInterceptor(
        function (hits){
            for (var i = 0; i < hits.length; i++) {
                hits[i]['highlighted_repr'] = "> "+hits[i]['highlighted_repr'];
            }
            return Promise.resolve(hits);
        }
    );