diff --git a/assets/js/custom.js b/assets/js/custom.js index 38a0211..94b163c 100644 --- a/assets/js/custom.js +++ b/assets/js/custom.js @@ -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(); \ No newline at end of file +// 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') + }) + }) + } +})