Sha256: 2064eee96fdff9841593e7f6e0f06643fb392ead4bab4dc7c0fe3014ad5d3a99
Contents?: true
Size: 1.42 KB
Versions: 21
Compression:
Stored size: 1.42 KB
Contents
// Custom JS to toggle the search form on mobile devices function searchToggle() { document.getElementById('searchIcon') ? document.addEventListener('click', function (event) { const searchIconElement = document.getElementById('searchImg'); const searchCollapse = document.getElementById('searchCollapse'); const mainNav = document.getElementById('mainNav'); const globalNav = document.getElementById('globalNav'); const searchIconBackgroundImage = searchIconElement.style.backgroundImage; const iconIsSearch = ( searchIconBackgroundImage.indexOf('assets/img/search.svg') != -1 ); const collapseAria = searchCollapse.getAttribute('aria-hidden'); // If the clicked element doesn't have the right selector, bail if (!event.target.matches('#searchIcon')) return; // Don't follow the link event.preventDefault(); iconIsSearch ? searchIconElement.style.backgroundImage = 'url("./assets/img/x.svg")' : searchIconElement.style.backgroundImage = 'url("./assets/img/search.svg")'; searchCollapse.classList.toggle('nav-global__search-collapse--visible'); (collapseAria === "true") ? searchCollapse.setAttribute('aria-hidden', 'false') : searchCollapse.setAttribute('aria-hidden', 'true'); mainNav.classList.toggle('local-nav--search-toggle'); globalNav.classList.toggle('nav-global--search-toggle'); }, false) : null; } module.exports = searchToggle;
Version data entries
21 entries across 21 versions & 1 rubygems