diff options
Diffstat (limited to 'assets/js/search.js')
-rw-r--r-- | assets/js/search.js | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/assets/js/search.js b/assets/js/search.js index 13727a3..c3c926a 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -130,15 +130,6 @@ function initializeSearch(index) { } } - function findQuery(query = 'query') { - const urlParams = new URLSearchParams(window.location.search); - if(urlParams.has(query)){ - let c = urlParams.get(query); - return c; - } - return ""; - } - function passiveSearch() { if(searchPageElement) { const searchTerm = findQuery(); @@ -208,27 +199,32 @@ function initializeSearch(index) { } function highlightSearchTerms(search, context, wrapper = 'mark', cssClass = '') { - let container = elem(context); - let reg = new RegExp("(" + search + ")", "gi"); - - function searchInNode(parentNode, search) { - forEach(parentNode, function (node) { - if (node.nodeType === 1) { - searchInNode(node, search); - } else if ( - node.nodeType === 3 && - reg.test(node.nodeValue) - ) { - let string = node.nodeValue.replace(reg, `<${wrapper} class="${cssClass}">$1</${wrapper}>`); - let span = document.createElement("span"); - span.dataset.searched = "true"; - span.innerHTML = string; - parentNode.replaceChild(span, node); - } - }); - }; + const query = findQuery() + if(query){ + + let container = elem(context); + let reg = new RegExp("(" + search + ")", "gi"); + + function searchInNode(parentNode, search) { + forEach(parentNode, function (node) { + if (node.nodeType === 1) { + searchInNode(node, search); + } else if ( + node.nodeType === 3 && + reg.test(node.nodeValue) + ) { + let string = node.nodeValue.replace(reg, `<${wrapper} class="${cssClass}">$1</${wrapper}>`); + let span = document.createElement("span"); + span.dataset.searched = "true"; + span.innerHTML = string; + parentNode.replaceChild(span, node); + } + }); + }; - searchInNode(container, search); + searchInNode(container, search); + + } } window.addEventListener('load', function() { |