document.addEventListener('DOMContentLoaded', function () {
var trendsLink = document.getElementById('trendsDropdown');
var dropdownMenu = trendsLink.nextElementSibling; // Assuming dropdown menu is the next sibling
trendsLink.addEventListener('click', function (event) {
// Prevent default navigation behavior for the click
event.preventDefault();
// Check if dropdown is already visible
if (dropdownMenu.style.display === 'block') {
// Redirect to the href of the link if dropdown is visible
window.location.href = trendsLink.href;
} else {
// Display the dropdown menu and prevent navigation
dropdownMenu.style.display = 'block';
dropdownMenu.style.opacity = '1';
dropdownMenu.style.visibility = 'visible';
}
});
// Hide dropdown when clicking outside
document.addEventListener('click', function (event) {
if (!event.target.matches('#trendsDropdown') && !event.target.closest('.dropdown-menu')) {
// Hide the dropdown menu if clicking outside
dropdownMenu.style.display = 'none';
dropdownMenu.style.opacity = '0';
dropdownMenu.style.visibility = 'hidden';
}
});
});