Sha256: e3d6b1f4771a077e8feebd3ab01005de5f3a718707c1db869184992fc0e83bc6
Contents?: true
Size: 1.17 KB
Versions: 91
Compression:
Stored size: 1.17 KB
Contents
(function() { window.GOVUK = window.GOVUK || {}; window.GOVUK.FilterComponents = function filterList(searchTerm) { var itemsToFilter = document.querySelectorAll('.component-list li'); for (var i = 0; i < itemsToFilter.length; i++ ) { var currentComponent = itemsToFilter[i]; var componentText = currentComponent.innerText.toLowerCase(); if (componentText.includes(searchTerm.toLowerCase())) { currentComponent.classList.remove('component-guide-hidden'); } else { currentComponent.classList.add('component-guide-hidden'); } } }; var formElement = document.querySelector('[data-module=filter-components]'); if (formElement) { var searchField = formElement.querySelector('input'); // We don't want the form to submit/refresh the page on enter key formElement.addEventListener('submit', function(e) { e.preventDefault(); }); searchField.addEventListener('input', function(e) { var searchTerm = searchField.value; window.GOVUK.FilterComponents(searchTerm); }); // trigger search if search query exists in query string on page load window.GOVUK.FilterComponents(searchField.value); } })();
Version data entries
91 entries across 91 versions & 1 rubygems