// ChromaZenith Studio - Main JavaScript document.addEventListener('DOMContentLoaded', function() { // Initialize Feather icons if (typeof feather !== 'undefined') { feather.replace(); } // Theme management initTheme(); // Showcase tabs initShowcaseTabs(); // Pricing toggle initPricingToggle(); // Smooth scroll for anchor links initSmoothScroll(); // Intersection Observer for animations initScrollAnimations(); // Mobile menu toggle (handled in web component, but backup here) initMobileMenu(); }); // Theme Management function initTheme() { // Check for saved theme preference or default to 'dark' const savedTheme = localStorage.getItem('theme') || 'dark'; document.documentElement.classList.add(savedTheme); // Theme toggle buttons (will be in shadow DOM, so we need to listen globally) document.addEventListener('theme-change', function(e) { const newTheme = e.detail.theme; document.documentElement.classList.remove('light', 'dark'); document.documentElement.classList.add(newTheme); localStorage.setItem('theme', newTheme); }); // Also check system preference if no saved preference if (!localStorage.getItem('theme')) { const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; const theme = prefersDark ? 'dark' : 'light'; document.documentElement.classList.remove('light', 'dark'); document.documentElement.classList.add(theme); } } // Showcase Tabs function initShowcaseTabs() { const tabsContainer = document.getElementById('showcase-tabs'); if (!tabsContainer) return; const tabButtons = tabsContainer.querySelectorAll('.tab-btn'); const panels = document.querySelectorAll('.tab-panel'); tabButtons.forEach(button => { button.addEventListener('click', function() { const targetTab = this.dataset.tab; // Update button states tabButtons.forEach(btn => { btn.classList.remove('active', 'bg-white', 'dark:bg-gray-800', 'shadow-lg', 'border-2', 'border-primary-500'); btn.classList.add('bg-transparent', 'border-2', 'border-transparent', 'hover:border-gray-200', 'dark:hover:border-gray-700'); // Remove colored border classes const iconDiv = btn.querySelector('div > div:first-child'); iconDiv.className = iconDiv.className.replace(/border-\w+-200 dark:border-\w+-800/, 'border-transparent'); }); this.classList.remove('bg-transparent', 'border-transparent', 'hover:border-gray-200', 'dark:hover:border-gray-700'); this.classList.add('active', 'bg-white', 'dark:bg-gray-800', 'shadow-lg', 'border-2', 'border-primary-500'); // Update panel visibility with fade effect panels.forEach(panel => { if (panel.dataset.panel === targetTab) { panel.classList.remove('hidden'); // Small delay to allow display:block to apply before opacity transition setTimeout(() => { panel.classList.add('active'); }, 10); } else { panel.classList.remove('active'); setTimeout(() => { panel.classList.add('hidden'); }, 300); } }); // Refresh feather icons in case new ones appeared if (typeof feather !== 'undefined') { feather.replace(); } }); }); } // Pricing Toggle function initPricingToggle() { const toggleButtons = document.querySelectorAll('.billing-toggle'); const priceAmounts = document.querySelectorAll('.price-amount'); toggleButtons.forEach(button => { button.addEventListener('click', function() { const billing = this.dataset.billing; // Update toggle button states toggleButtons.forEach(btn => { btn.classList.remove('active', 'bg-white', 'dark:bg-gray-700', 'text-gray-900', 'dark:text-white', 'shadow-sm'); btn.classList.add('text-gray-600', 'dark:text-gray-400'); }); this.classList.remove('text-gray-600', 'dark:text-gray-400'); this.classList.add('active', 'bg-white', 'dark:bg-gray-700', 'text-gray-900', 'dark:text-white', 'shadow-sm'); // Animate price changes priceAmounts.forEach(price => { const newAmount = price.dataset[billing]; animatePrice(price, newAmount); }); }); }); } function animatePrice(element, newAmount) { const currentText = element.textContent; const isYearly = newAmount !== '0'; // Simple fade out/in animation element.style.opacity = '0'; element.style.transform = 'translateY(-10px)'; setTimeout(() => { element.textContent = '$' + newAmount; element.style.opacity = '1'; element.style.transform = 'translateY(0)'; }, 200); } // Smooth Scroll function initSmoothScroll() { document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function(e) { const href = this.getAttribute('href'); if (href === '#') return; const target = document.querySelector(href); if (target) { e.preventDefault(); const headerOffset = 80; const elementPosition = target.getBoundingClientRect().top; const offsetPosition = elementPosition + window.pageYOffset - headerOffset; window.scrollTo({ top: offsetPosition, behavior: 'smooth' }); } }); }); } // Scroll Animations function initScrollAnimations() { const observerOptions = { root: null, rootMargin: '0px', threshold: 0.1 }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate-in'); observer.unobserve(entry.target); } }); }, observerOptions); // Observe elements with animation classes document.querySelectorAll('.group, .card-lift, .tab-btn').forEach(el => { el.style.opacity = '0'; el.style.transform = 'translateY(20px)'; el.style.transition = 'opacity 0.6s ease, transform 0.6s ease'; observer.observe(el); }); // Add animate-in class styles const style = document.createElement('style'); style.textContent = ` .animate-in { opacity: 1 !important; transform: translateY(0) !important; } `; document.head.appendChild(style); } // Mobile Menu function initMobileMenu() { // The mobile menu is handled in the web component, but we can add // click-outside-to-close functionality here as a backup document.addEventListener('click', function(e) { const nav = document.querySelector('app-nav'); if (!nav) return; const shadow = nav.shadowRoot; if (!shadow) return; const mobileMenu = shadow.querySelector('.mobile-menu'); const menuButton = shadow.querySelector('.menu-button'); if (!mobileMenu || !menuButton) return; const isClickInside = nav.contains(e.target) || e.target.closest('app-nav'); if (!isClickInside && !mobileMenu.classList.contains('hidden')) { mobileMenu.classList.add('hidden'); const icon = menuButton.querySelector('i'); if (icon) { icon.setAttribute('data-feather', 'menu'); feather.replace(); } } }); } // Utility: Throttle function function throttle(func, limit) { let inThrottle; return function(...args) { if (!inThrottle) { func.apply(this, args); inThrottle = true; setTimeout(() => inThrottle = false, limit); } }; } // Utility: Debounce function function debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; } // Expose utilities globally window.ChromaUtils = { throttle, debounce, setTheme: function(theme) { document.documentElement.classList.remove('light', 'dark'); document.documentElement.classList.add(theme); localStorage.setItem('theme', theme); }, getTheme: function() { return document.documentElement.classList.contains('dark') ? 'dark' : 'light'; }, toggleTheme: function() { const current = this.getTheme(); const next = current === 'dark' ? 'light' : 'dark'; this.setTheme(next); return next; } };