Spaces:
Running
Running
File size: 1,556 Bytes
9076e9b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | // Shared JavaScript across all pages
document.addEventListener('DOMContentLoaded', function() {
// Initialize tooltips for all elements with data-tooltip attribute
const tooltipElements = document.querySelectorAll('[data-tooltip]');
tooltipElements.forEach(el => {
const tooltipText = el.getAttribute('data-tooltip');
el.addEventListener('mouseenter', () => {
const tooltip = document.createElement('div');
tooltip.className = 'absolute z-50 bg-gray-800 text-white text-sm px-2 py-1 rounded whitespace-nowrap';
tooltip.textContent = tooltipText;
const rect = el.getBoundingClientRect();
tooltip.style.top = `${rect.top - 30}px`;
tooltip.style.left = `${rect.left + rect.width/2}px`;
tooltip.style.transform = 'translateX(-50%)';
tooltip.id = 'current-tooltip';
document.body.appendChild(tooltip);
});
el.addEventListener('mouseleave', () => {
const tooltip = document.getElementById('current-tooltip');
if (tooltip) {
tooltip.remove();
}
});
});
// Add active class to current page link in navbar
const currentPath = window.location.pathname;
const navLinks = document.querySelectorAll('custom-navbar a');
navLinks.forEach(link => {
if (link.getAttribute('href') === currentPath) {
link.classList.add('font-semibold', 'text-blue-100');
}
});
}); |