Sha256: 10a1ce1d2457896c6625d3c3a6fc8f5870b1178f8e27b6a79ed6b29a0162300a

Contents?: true

Size: 893 Bytes

Versions: 55

Compression:

Stored size: 893 Bytes

Contents

const NAV_LINKS_SELECTOR = '.nav-link:not(.dropdown-toggle)';  // Bootstrap 4 class
const MENU_COLLAPSE_JQUERY = $('#headerGlobalNavbarContent'); // Bootstrap 4 crap that requires $() w/ an ID from the HTML
const MENU_COLLAPSE = 'headerGlobalNavbarContent';  // ID from the HTML
const HIDE = 'hide';  // Bootstrap 4 class
const SHOW = 'show';  // Bootstrap 4 class

function clickHandlerFunction(e) {
  if ( !e.target.matches(NAV_LINKS_SELECTOR) || e.target.classList.contains('dropdown-toggle') )  // Bail out of the rest of the code if the click event's target is not what we want!
    return;

  const menuIsOpen = document.getElementById(MENU_COLLAPSE).classList.contains(SHOW) ? true : false;

  if (menuIsOpen) {
    MENU_COLLAPSE_JQUERY.collapse(HIDE);
  }
}

function closeMenuOnClick() {
  document.addEventListener('click', clickHandlerFunction);
}

export default closeMenuOnClick;

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
kcc-gem-theme-2.26.2 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.26.1 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.26.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.25.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.24.4 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.24.3 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.24.2 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.24.1 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.24.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.23.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.22.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.21.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.20.3 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.20.2 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.20.1 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.20.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.19.8 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.19.7 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.19.6 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.19.5 assets/js/nav/megaNav/closeMegaNavOnClick.js