From ed6595aae61a782fb4f4f92329e432ecd932a0db Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sat, 22 Oct 2022 22:10:19 +0100 Subject: [PATCH] fix: algolia integration when common queries disabled --- modules/wowchemy/assets/js/algolia-search.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/wowchemy/assets/js/algolia-search.js b/modules/wowchemy/assets/js/algolia-search.js index 9d1d140d..eb2f9465 100644 --- a/modules/wowchemy/assets/js/algolia-search.js +++ b/modules/wowchemy/assets/js/algolia-search.js @@ -10,6 +10,7 @@ import algoliasearch from 'https://cdn.jsdelivr.net/npm/algoliasearch@4/dist/alg // import instantsearch from 'https://cdn.jsdelivr.net/npm/instantsearch.js@4/es/index.js' // import {searchBox, infiniteHits} from 'https://cdn.jsdelivr.net/npm/instantsearch.js@4/es/widgets/index.js'; +// Optional integration of Algolia Search Analytics (configured in site params) if (algoliaConfig.analytics) { let ALGOLIA_INSIGHTS_SRC = 'https://cdn.jsdelivr.net/npm/search-insights@2.0.2/dist/search-insights.iife.min.js'; @@ -44,7 +45,11 @@ document.addEventListener('DOMContentLoaded', () => { $('body').addClass('searching'); $('.search-results').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 200); let commonQueries = document.querySelector('#search-common-queries'); - commonQueries.style.display = 'none'; + + // Displaying common search queries in the search modal is an optional feature, so check if the element exists. + if (commonQueries !== null) { + commonQueries.style.display = 'none'; + } } if (typeof instantsearch === 'function' && $('#search-box').length) { @@ -100,9 +105,13 @@ document.addEventListener('DOMContentLoaded', () => { queryHook(query, refine) { if (query === '') { searchResults.style.display = 'none'; - commonQueries.style.display = 'block'; + if (commonQueries !== null) { + commonQueries.style.display = 'block'; + } } else { - commonQueries.style.display = 'none'; + if (commonQueries !== null) { + commonQueries.style.display = 'none'; + } searchResults.style.display = 'block'; } if (timerId) {