// Smooth scrolling for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); // Initialize animations on scroll const animateOnScroll = () => { const elements = document.querySelectorAll('.fade-in, .slide-up'); elements.forEach(element => { const elementPosition = element.getBoundingClientRect().top; const windowHeight = window.innerHeight; if (elementPosition < windowHeight - 100) { element.style.opacity = '1'; element.style.transform = 'translateY(0)'; } }); }; window.addEventListener('scroll', animateOnScroll); window.addEventListener('load', animateOnScroll); // Theme switcher functionality const themeToggle = document.getElementById('theme-toggle'); if (themeToggle) { themeToggle.addEventListener('click', () => { document.documentElement.classList.toggle('dark'); localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? 'dark' : 'light'); }); } // Check for saved theme preference if (localStorage.getItem('theme') === 'light') { document.documentElement.classList.remove('dark'); } else { document.documentElement.classList.add('dark'); } // CodeDex specific initialization document.addEventListener('DOMContentLoaded', () => { // Add active class to current nav link const currentPath = window.location.pathname; const navLinks = document.querySelectorAll('custom-navbar a, custom-footer a'); navLinks.forEach(link => { if (link.getAttribute('href') === currentPath) { link.classList.add('active'); } }); // Initialize code editor if present if (document.querySelector('.code-editor')) { // This would be replaced with actual CodeMirror or Monaco editor initialization console.log('Code editor initialized'); } });