File size: 9,369 Bytes
375fcbe | 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | // 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;
}
}; |