|
16 | 16 | advancedSyntaxFeatures: ['exactPhrase'],
|
17 | 17 | }
|
18 | 18 | var searchField = document.getElementById(config.searchFieldId || 'search')
|
19 |
| - var filterInput = searchField.querySelector('.filter input') |
20 |
| - filterInput.checked = window.localStorage.getItem(SEARCH_FILTER_ACTIVE_KEY) === 'true' |
21 | 19 | var controller = docsearch({
|
22 | 20 | appId: config.appId,
|
23 | 21 | apiKey: config.apiKey,
|
|
27 | 25 | algoliaOptions: algoliaOptions,
|
28 | 26 | transformData: protectHitOrder,
|
29 | 27 | queryHook:
|
30 |
| - filterInput && |
| 28 | + searchField.classList.contains('has-filter') && |
31 | 29 | function (query) {
|
32 |
| - controller.algoliaOptions = filterInput.checked |
33 |
| - ? Object.assign({}, algoliaOptions, { facetFilters: [filterInput.dataset.facetFilter] }) |
| 30 | + controller.algoliaOptions = typeahead.$facetFilterInput.prop('checked') |
| 31 | + ? Object.assign({}, algoliaOptions, { facetFilters: [typeahead.$facetFilterInput.data('facetFilter')] }) |
34 | 32 | : algoliaOptions
|
35 | 33 | },
|
36 | 34 | })
|
|
48 | 46 | menu.on('mousedown.aa', suggestionSelector, onSuggestionMouseDown.bind(dropdown))
|
49 | 47 | menu.off('mouseenter.aa')
|
50 | 48 | menu.off('mouseleave.aa')
|
51 |
| - if (filterInput) filterInput.addEventListener('change', toggleFilter.bind(typeahead)) |
| 49 | + typeahead.$facetFilterInput = input |
| 50 | + .closest('#' + searchField.id) |
| 51 | + .find('.filter input') |
| 52 | + .on('change', toggleFilter.bind(typeahead)) |
| 53 | + .prop('checked', window.localStorage.getItem(SEARCH_FILTER_ACTIVE_KEY) === 'true') |
52 | 54 | monitorCtrlKey(input, dropdown)
|
53 | 55 | searchField.addEventListener('click', confineEvent)
|
54 | 56 | document.documentElement.addEventListener('click', clearSearch.bind(typeahead))
|
|
0 commit comments