mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-28 11:49:13 -04:00
subnav
This commit is contained in:
29
app/assets/javascripts/subNav.js
Normal file
29
app/assets/javascripts/subNav.js
Normal file
@@ -0,0 +1,29 @@
|
||||
(function(window) {
|
||||
"use strict";
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const sideNavLinks = document.querySelectorAll('.usa-sidenav__item');
|
||||
const currentURL = window.location.pathname;
|
||||
|
||||
sideNavLinks.forEach(link => {
|
||||
const sublist = link.querySelector('.usa-sidenav__sublist');
|
||||
const parentLink = link.querySelector('a');
|
||||
|
||||
const isMatch = parentLink && sublist && currentURL === parentLink.getAttribute('href');
|
||||
if (isMatch) {
|
||||
sublist.classList.replace('display-none', 'display-block');
|
||||
}
|
||||
|
||||
link.addEventListener('click', function(event) {
|
||||
if (sublist && event.target === parentLink) {
|
||||
event.preventDefault();
|
||||
|
||||
sublist.classList.toggle('display-none');
|
||||
sublist.classList.toggle('display-block');
|
||||
|
||||
setTimeout(() => window.location.href = parentLink.href, 100);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})(window);
|
||||
Reference in New Issue
Block a user