🚀feat(js) aktualisiere benutzerfreundliches Dropdown-Menü

This commit is contained in:
Andreas Hnida 2024-04-01 08:59:40 +02:00
commit b1be0b761d

View file

@ -1,10 +1,49 @@
function removeEmptyParagraphs() {
const paragraphs = document.querySelectorAll('p');
paragraphs.forEach(paragraph => {
if (!paragraph.textContent.trim() && !paragraph.querySelector('i')) {
paragraph.remove();
}
});
const paragraphs = document.querySelectorAll('p')
paragraphs.forEach((paragraph) => {
if (!paragraph.textContent.trim() && !paragraph.querySelector('i')) {
paragraph.remove()
}
})
}
removeEmptyParagraphs();
// removeEmptyParagraphs();
document.addEventListener('DOMContentLoaded', function () {
if ('ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0) {
const navDropdowns = document.querySelectorAll('.nav-dropdown')
navDropdowns.forEach(function (dropdown) {
const dropdownLink = dropdown.querySelector('a')
const dropdownIcon = dropdown.querySelector('svg')
const dropdownList = dropdown.querySelector('.nav-dropdown-list')
let clickCount = 0
dropdownLink.addEventListener('click', function (event) {
if (dropdownList) {
event.preventDefault()
clickCount++
if (clickCount % 2 === 1) {
dropdownList.classList.add('visible', 'opacity-100')
} else {
window.location.href = dropdownLink.getAttribute('href')
}
}
})
dropdownIcon.addEventListener('click', function (event) {
// If the dropdown is already open, clicking
// on the icon should close it. Otherwise
// clicking on the icon should open it.
console.log('clickCount', clickCount)
event.preventDefault()
event.stopPropagation()
dropdown.classList.toggle('active')
dropdownList.classList.toggle('visible')
dropdownList.classList.toggle('opacity-100')
})
})
}
})