Sha256: 3d6bc5dd5353e54923ab62b3e4ccfcb22a92d4dafeacbbc854a29d58800da860

Contents?: true

Size: 1.19 KB

Versions: 22

Compression:

Stored size: 1.19 KB

Contents

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

function hideBootstrapMenu() {
  MENU_COLLAPSE_JQUERY.collapse(HIDE);
}

function checkIfMenuIsOpen() {
  if ( document.getElementById(MENU_COLLAPSE).classList.contains(SHOW) ) {
    return true;
  }
  return false;
}

function hideMenuIfOpen(menuIsOpen) {
  if ( menuIsOpen ) {
    hideBootstrapMenu();
  } else {
    return;
  }
}

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

  const menuIsOpen = checkIfMenuIsOpen();

  hideMenuIfOpen(menuIsOpen);
}

function addEventListenerFunction(element, clickEvent) {
  element.addEventListener(clickEvent, clickHandlerFunction, false);
}

function closeMenuOnClick() {
  const clickEvent = 'click';
  const element = document;

  addEventListenerFunction(element, clickEvent);
}

export default closeMenuOnClick;

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
kcc-gem-theme-1.30.9 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.29.9 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.28.9 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.28.8 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.28.7 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.27.7 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.27.6 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.26.6 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.25.6 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.25.5 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.24.5 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.23.5 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.22.5 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.21.5 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.20.5 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.20.4 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.20.3 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.20.2 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.19.2 assets/js/theme/src/closeMenuOnClick.js
kcc-gem-theme-1.18.2 assets/js/theme/script/closeMenuOnClick.js