File size: 3,146 Bytes
3d4a94f | 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | document.addEventListener('DOMContentLoaded', function() {
// Dark mode toggle
const darkModeToggle = document.createElement('button');
darkModeToggle.className = 'p-2 rounded-full focus:outline-none';
darkModeToggle.innerHTML = '<i data-feather="moon"></i>';
darkModeToggle.setAttribute('aria-label', 'Toggle dark mode');
// Check for saved user preference or system preference
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
const currentTheme = localStorage.getItem('theme');
if (currentTheme === 'dark' || (!currentTheme && prefersDarkScheme.matches)) {
document.documentElement.classList.add('dark');
darkModeToggle.innerHTML = '<i data-feather="sun"></i>';
}
// Insert toggle into navbar
const nav = document.querySelector('custom-navbar');
if (nav) {
nav.shadowRoot.querySelector('.nav-container').appendChild(darkModeToggle);
}
// Toggle functionality
darkModeToggle.addEventListener('click', function() {
const isDark = document.documentElement.classList.toggle('dark');
localStorage.setItem('theme', isDark ? 'dark' : 'light');
darkModeToggle.innerHTML = isDark ? '<i data-feather="sun"></i>' : '<i data-feather="moon"></i>';
feather.replace();
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Initialize tooltips
document.querySelectorAll('.tooltip').forEach(el => {
el.addEventListener('mouseenter', function() {
const tooltip = this.querySelector('.tooltip-text');
if (tooltip) {
tooltip.style.visibility = 'visible';
tooltip.style.opacity = '1';
}
});
el.addEventListener('mouseleave', function() {
const tooltip = this.querySelector('.tooltip-text');
if (tooltip) {
tooltip.style.visibility = 'hidden';
tooltip.style.opacity = '0';
}
});
});
// Animate cards when they come into view
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('card-animate');
observer.unobserve(entry.target);
}
});
}, observerOptions);
document.querySelectorAll('.bg-white, .bg-gray-800').forEach(card => {
observer.observe(card);
});
}); |