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.37.1 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.37.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.36.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.35.5 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.35.4 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.35.3 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.35.2 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.35.1 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.35.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.34.2 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.34.1 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.34.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.33.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.32.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.31.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.30.1 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.30.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.29.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.28.0 assets/js/nav/megaNav/closeMegaNavOnClick.js
kcc-gem-theme-2.27.0 assets/js/nav/megaNav/closeMegaNavOnClick.js