// calls the switfttype engine to use the fetch new results var reloadResults = function () { Swiftype.reloadResults(); }; // the barebones search configuration var searchConfig = { page: { category: undefined, } }; // passed into the swift type engine when the reloadResults is called // doc source pages are of the page DocumentType. Category is a class applied through a header tag with a name specific to the filters applied. $(document).ready(function () { readFilters = function () { return { page: { category: window.searchConfig.page.category } } }; }); //defines the results which display in the results container var defaultRenderFunction = function (document_type, item) { return '

' + item['title'] + '

'; } // returns the title/body of the item. Body will be a substring if over a certain number of characters var customRenderFunction = function (document_type, item) { //returns title of article with embedded url var out = '' + item['title'] + ''; //defines body and limits var body; if (item.highlight['body']) { body = item['body'].length > 300 ? item.highlight['body'].substr(0, 300) + '...' : item.highlight['body']; } else { body = item['body'].length > 300 ? item['body'].substr(0, 300) + '...' : item['body']; }; return out.concat('

' + body + '

'); }; //Custom paginator will present prev, next plus page numbers //if less than 6 pages it will show all //if greather than 6 it will show 1, elipsis, three pages centered on current, elipsis, then last var customRenderPaginationForType = function (type, currentPage, totalPages) { let active; let pageCutLow = currentPage - 1; let pageCutHigh = currentPage + 1; var pages = '
'; return pages; }; var customPostRenderFunction = function (data) { var totalResultCount = 0; var $resultContainer = this.getContext().resultContainer; var spellingSuggestion = null; if (data['info']) { $.each(data['info'], function (index, value) { totalResultCount += value['total_result_count']; if (value['spelling_suggestion']) { spellingSuggestion = value['spelling_suggestion']['text']; } }); } if (totalResultCount === 0) { $resultContainer.html("
No results found.
"); } if (spellingSuggestion !== null) { $resultContainer.append('
Did you mean ' + spellingSuggestion + '?
'); } }; //filter click function $(document).ready(function () { $('.search-filter').on('click', function () { // we capture the variable as the code underneath will change the value to false var checked = this.checked; // removes all the other checkboxes, each result only has one category $('.search-filter').each(function () { $(this).prop('checked', false); }); // updates the UI to whether this checkbox should be checked or not $(this).prop('checked', checked); // if the checkbox is checked, we update the global variable to the `value` attribute so it filters by that window.searchConfig.page.category = checked ? $(this).data('value') : undefined; reloadResults(); }); });