diff options
Diffstat (limited to 'scripts/src/main-nav.js')
-rw-r--r-- | scripts/src/main-nav.js | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/scripts/src/main-nav.js b/scripts/src/main-nav.js index fa6f25a..c85cb4f 100644 --- a/scripts/src/main-nav.js +++ b/scripts/src/main-nav.js @@ -5,44 +5,46 @@ function hideOnClickOutsided(element, btn) { const outsideClickListener = event => { if (!element.contains(event.target) && (event.target.id != btn)) { // or use: event.target.closest(selector) === null if (isVisible(element)) { - element.classList.remove('active') - removeClickListener() + element.classList.remove('active'); + removeClickListener(); } } - } + }; const removeClickListener = () => { - document.removeEventListener('click', outsideClickListener) - } - document.addEventListener('click', outsideClickListener) + document.removeEventListener('click', outsideClickListener); + }; + document.addEventListener('click', outsideClickListener); } -const isVisible = elem => !!elem && !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ) // source (2018-03-11): https://github.com/jquery/jquery/blob/master/src/css/hiddenVisibleSelectors.js +const isVisible = elem => !!elem && !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ); // source (2018-03-11): https://github.com/jquery/jquery/blob/master/src/css/hiddenVisibleSelectors.js //---------------------------------------- //Initialize main menu bar with progressive enhancements +//if we find the menu items //---------------------------------------------- // Account Menu -var account_a = document.getElementById("account-menu"); -var account_div = document.getElementById("user-menu"); -//Add button function -account_a.addEventListener('click', function(e){ - e.preventDefault(); - account_div.classList.toggle('active') - account_div.focus(); - hideOnClickOutsided(account_div, account_a.id); -}, false); - -// Notebooks Menu -var notebook_a = document.getElementById("notebook-menu-link"); -var notebook_div = document.getElementById("notebooks-menu"); -//Add button function -notebook_a.addEventListener('click', function(e){ - e.preventDefault(); - notebook_div.classList.toggle('active') - notebook_div.focus(); - hideOnClickOutsided(notebook_div, notebook_a.id); -}, false); +if (document.getElementById('account-menu')) { + var account_a = document.getElementById('account-menu'); + var account_div = document.getElementById('user-menu'); + //Add button function + account_a.addEventListener('click', function(e){ + e.preventDefault(); + account_div.classList.toggle('active'); + account_div.focus(); + hideOnClickOutsided(account_div, account_a.id); + }, false); + // Notebooks Menu + var notebook_a = document.getElementById('notebook-menu-link'); + var notebook_div = document.getElementById('notebooks-menu'); + //Add button function + notebook_a.addEventListener('click', function(e){ + e.preventDefault(); + notebook_div.classList.toggle('active'); + notebook_div.focus(); + hideOnClickOutsided(notebook_div, notebook_a.id); + }, false); +} //function buildNotebookMenu () { // var data = JSON.parse(this.responseText); |