Sha256: 5491a0e32e19dfc9a104aa676aeb2a148d8af452ca7404bd0f9b5d7e690e0c0e

Contents?: true

Size: 1.16 KB

Versions: 379

Compression:

Stored size: 1.16 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

379 entries across 379 versions & 1 rubygems

Version Path
govuk_publishing_components-49.1.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-49.0.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-48.0.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-47.0.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-46.4.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-46.3.1 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-46.3.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-46.2.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-46.1.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-46.0.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.10.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.9.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.8.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.7.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.6.1 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.6.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.5.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.4.1 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.4.0 app/assets/javascripts/component_guide/filter-components.js
govuk_publishing_components-45.3.0 app/assets/javascripts/component_guide/filter-components.js