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