|
28 | 28 |
|
29 | 29 | .htmlsitemap-index-index .sitemap-item-type {margin-bottom: 40px;} |
30 | 30 | .htmlsitemap-index-index .sitemap-item-type > h2 {margin: 0 0 20px;} |
31 | | - .htmlsitemap-index-index .sitemap-item-type .highlight-result {color: red;} |
| 31 | + [class*="htmlsitemap-"] .highlight-result {color: red;} |
32 | 32 |
|
33 | 33 | /* Category */ |
34 | 34 | [class*="htmlsitemap-"] .widget.block-categories .accordion {margin-bottom: 20px;} |
|
60 | 60 |
|
61 | 61 | </style> |
62 | 62 | <?php $script = " |
63 | | - require(['jquery'], function($) { |
64 | | -
|
| 63 | + document.addEventListener('DOMContentLoaded', function() { |
65 | 64 | var searchQuery = ''; |
66 | 65 |
|
67 | 66 | initSearch(); |
68 | 67 |
|
69 | 68 | function initSearch() { |
70 | | - $('#html-sitemap-search').keyup(function(el) { |
71 | | - var val = el.target.value; |
| 69 | + var searchInput = document.getElementById('html-sitemap-search'); |
| 70 | +
|
| 71 | + // Handle keyup event on the search input |
| 72 | + searchInput.addEventListener('keyup', function(event) { |
| 73 | + var val = event.target.value; |
72 | 74 |
|
73 | | - if (searchQuery != val.toLocaleLowerCase()) { |
| 75 | + if (searchQuery !== val.toLocaleLowerCase()) { |
74 | 76 | findItems(val); |
75 | 77 | } |
76 | 78 | }); |
77 | 79 |
|
78 | | - $('.sitemap-item-section a').each(function (key, el) { |
| 80 | + // Store original content for each link |
| 81 | + var links = document.querySelectorAll('.sitemap-item-section a'); |
| 82 | + links.forEach(function(el) { |
79 | 83 | el.originalTextContent = el.innerText ? el.innerHTML : el.textContent; |
80 | 84 | }); |
81 | 85 | } |
82 | 86 |
|
83 | 87 | function findItems(query) { |
84 | | - searchQuery = query.replace(/^\s+/, '').replace(/\s+$/, '').toLowerCase(); |
| 88 | + searchQuery = query.trim().toLowerCase(); |
85 | 89 |
|
86 | | - $('.sitemap-item-section').each(function(key, el) { |
| 90 | + var sections = document.querySelectorAll('.sitemap-item-section'); |
| 91 | + sections.forEach(function(section) { |
87 | 92 | var noResults = true; |
88 | 93 |
|
89 | | - $(this).find('a').each(function(key, el) { |
| 94 | + var links = section.querySelectorAll('a'); |
| 95 | + links.forEach(function(el) { |
90 | 96 | el.textContent = el.originalTextContent.replace(/&/g, '&'); |
91 | | - if (searchQuery.replace(/\s+/, '') != '') { |
92 | | - if (el.originalTextContent.toLowerCase().indexOf(searchQuery) == -1) { |
93 | | - $(el).hide(); |
| 97 | +
|
| 98 | + if (searchQuery !== '') { |
| 99 | + if (el.originalTextContent.toLowerCase().indexOf(searchQuery) === -1) { |
| 100 | + el.style.display = 'none'; |
94 | 101 | } else { |
95 | | - $(el).show(); |
| 102 | + el.style.display = ''; |
96 | 103 | noResults = false; |
97 | | - highlightResult($(el).get(0), searchQuery, 'highlight-result'); |
| 104 | + highlightResult(el, searchQuery, 'highlight-result'); |
98 | 105 | } |
99 | 106 | } else { |
100 | | - $(el).show(); |
| 107 | + el.style.display = ''; |
101 | 108 | noResults = false; |
102 | 109 | } |
103 | 110 | }); |
104 | 111 |
|
105 | | - if (noResults) { |
106 | | - $(this).hide(); |
107 | | - } else { |
108 | | - $(this).show(); |
109 | | - } |
| 112 | + section.style.display = noResults ? 'none' : ''; |
110 | 113 | }); |
111 | 114 | } |
112 | 115 |
|
113 | 116 | function highlightResult(element, term, className) { |
| 117 | +
|
114 | 118 | className = className || 'highlight'; |
115 | 119 | term = (term || '').toUpperCase(); |
116 | | - if (term.replace(/\s+/, '') == '') { |
117 | | - return false |
| 120 | +
|
| 121 | + if ('' === term) { |
| 122 | + return false; |
118 | 123 | } |
119 | 124 |
|
120 | | - if (element.nodeType == Node.TEXT_NODE) { |
| 125 | + if (element.nodeType === Node.TEXT_NODE) { |
121 | 126 | var pos = element.data.toUpperCase().indexOf(term); |
122 | 127 | if (pos >= 0) { |
123 | 128 | var searchResult = element.splitText(pos), |
|
127 | 132 | spanWrapper.className = className; |
128 | 133 | spanWrapper.appendChild(searchResult.cloneNode(true)); |
129 | 134 | searchResult.parentNode.replaceChild(spanWrapper, searchResult); |
130 | | -
|
131 | 135 | } |
132 | | - } else if (element.nodeType == Node.ELEMENT_NODE && element.childNodes && !/(script|style)/i.test(element.tagName)) { |
| 136 | + } else if (element.nodeType === Node.ELEMENT_NODE && element.childNodes && !/(script|style)/i.test(element.tagName)) { |
133 | 137 | for (var i = 0; i < element.childNodes.length; ++i) { |
134 | 138 | i += highlightResult(element.childNodes[i], term, className); |
135 | 139 | } |
136 | 140 | } |
137 | 141 | }; |
138 | 142 | }); |
139 | 143 | ";?> |
140 | | - |
141 | 144 | <?= /* @noEscape */ $mfSecureRenderer->renderTag('script', [], $script, false) ?> |
0 commit comments