initial commit
This commit is contained in:
22
bootstrap-nav-closer.js
vendored
Normal file
22
bootstrap-nav-closer.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
export const bootstrapNavCloser = () => {
|
||||
const closeNav = (navSelector) => {
|
||||
const nav = document.getElementById(navSelector)
|
||||
if (nav) {
|
||||
if (nav.classList.contains('show')) {
|
||||
nav.classList.remove('show')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', (e) => {
|
||||
const nav = document.querySelector('.navbar-toggler').dataset['bsTarget'].substring(1)
|
||||
|
||||
if (e.target.attributes.id) {
|
||||
if (!e.target.attributes.id.textContent.matchAll([nav, 'dropdown'])) {
|
||||
closeNav(nav)
|
||||
}
|
||||
} else {
|
||||
closeNav(nav)
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user