Spaces:
Running
Running
| // Shared JavaScript functions | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize dark mode toggle | |
| const darkModeToggle = document.getElementById('darkModeToggle'); | |
| if (darkModeToggle) { | |
| darkModeToggle.addEventListener('click', function() { | |
| document.documentElement.classList.toggle('dark'); | |
| localStorage.setItem('darkMode', document.documentElement.classList.contains('dark')); | |
| }); | |
| } | |
| // Check for saved dark mode preference | |
| if (localStorage.getItem('darkMode') === 'true') { | |
| document.documentElement.classList.add('dark'); | |
| } | |
| // Initialize tooltips | |
| const tooltipElements = document.querySelectorAll('[data-tooltip]'); | |
| tooltipElements.forEach(el => { | |
| el.addEventListener('mouseenter', showTooltip); | |
| el.addEventListener('mouseleave', hideTooltip); | |
| }); | |
| // Smooth scroll for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| document.querySelector(this.getAttribute('href')).scrollIntoView({ | |
| behavior: 'smooth' | |
| }); | |
| }); | |
| }); | |
| }); | |
| function showTooltip(e) { | |
| const tooltipText = this.getAttribute('data-tooltip'); | |
| const tooltip = document.createElement('div'); | |
| tooltip.className = 'absolute z-50 bg-gray-900 text-white text-xs px-2 py-1 rounded whitespace-nowrap'; | |
| tooltip.textContent = tooltipText; | |
| this.appendChild(tooltip); | |
| const rect = this.getBoundingClientRect(); | |
| tooltip.style.top = `${rect.top - 30}px`; | |
| tooltip.style.left = `${rect.left + rect.width / 2 - tooltip.offsetWidth / 2}px`; | |
| this.tooltip = tooltip; | |
| } | |
| function hideTooltip() { | |
| if (this.tooltip) { | |
| this.tooltip.remove(); | |
| } | |
| } | |
| // Debounce function | |
| function debounce(func, wait, immediate) { | |
| let timeout; | |
| return function() { | |
| const context = this, args = arguments; | |
| const later = function() { | |
| timeout = null; | |
| if (!immediate) func.apply(context, args); | |
| }; | |
| const callNow = immediate && !timeout; | |
| clearTimeout(timeout); | |
| timeout = setTimeout(later, wait); | |
| if (callNow) func.apply(context, args); | |
| }; | |
| } |