CoolFace
Apppublic

tim4087/stellardocs-cosmic-knowledge-base

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
script.js54 linesDownload Raw Back to root
1// Mobile menu toggle2document.getElementById('mobile-menu-button').addEventListener('click', function() {3    const menu = document.getElementById('mobile-menu');4    menu.classList.toggle('hidden');5});6 7// Smooth scrolling for anchor links8document.querySelectorAll('a[href^="#"]').forEach(anchor => {9    anchor.addEventListener('click', function (e) {10        e.preventDefault();11        12        document.querySelector(this.getAttribute('href')).scrollIntoView({13            behavior: 'smooth'14        });15    });16});17 18// Add active class to current section in sidebar19const sections = document.querySelectorAll('section[id]');20const navLinks = document.querySelectorAll('aside nav a');21 22window.addEventListener('scroll', () => {23    let current = '';24    25    sections.forEach(section => {26        const sectionTop = section.offsetTop;27        const sectionHeight = section.clientHeight;28        29        if (pageYOffset >= (sectionTop - 100)) {30            current = section.getAttribute('id');31        }32    });33    34    navLinks.forEach(link => {35        link.classList.remove('bg-gray-700', 'text-white');36        if (link.getAttribute('href') === `#${current}`) {37            link.classList.add('bg-gray-700', 'text-white');38        }39    });40});41 42// Theme switcher (for future use)43function toggleTheme() {44    const html = document.documentElement;45    html.classList.toggle('dark');46    localStorage.setItem('theme', html.classList.contains('dark') ? 'dark' : 'light');47}48 49// Check for saved theme preference50if (localStorage.getItem('theme') === 'dark' || (!localStorage.getItem('theme') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {51    document.documentElement.classList.add('dark');52} else {53    document.documentElement.classList.remove('dark');54}