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

Version Path
govuk_publishing_components-21.48.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.47.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.46.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.45.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.44.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.43.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.42.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.41.4 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.41.3 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.41.2 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.41.1 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.41.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.40.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.39.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.38.5 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.38.4 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.38.3 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.38.2 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.38.1 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-21.38.0 app/assets/javascripts/component_guide/filter-components.js