File size: 7,907 Bytes
bddcfed | 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 | // ===== SHARED JS - AI Chapter Forge =====
// Initialize Lucide icons
function initIcons() {
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
}
// ===== CURSOR GLOW =====
function initCursorGlow() {
const cursorGlow = document.getElementById('cursorGlow');
if (!cursorGlow) return;
document.addEventListener('mousemove', (e) => {
cursorGlow.style.left = e.clientX + 'px';
cursorGlow.style.top = e.clientY + 'px';
cursorGlow.style.opacity = '1';
});
}
// ===== SCROLL REVEAL =====
function initScrollReveal() {
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('active');
}
});
}, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' });
document.querySelectorAll('.reveal, .reveal-left, .reveal-scale').forEach(el => {
revealObserver.observe(el);
});
}
// ===== ANIMATED COUNTERS =====
function initCounters() {
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('counted')) {
entry.target.classList.add('counted');
const target = parseInt(entry.target.getAttribute('data-target'));
const suffix = entry.target.getAttribute('data-suffix') || '';
if (target) {
animateCounter(entry.target, target, suffix);
}
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.counter').forEach(el => counterObserver.observe(el));
}
function animateCounter(el, target, suffix) {
const duration = 2000;
const start = performance.now();
const step = (now) => {
const elapsed = now - start;
const progress = Math.min(elapsed / duration, 1);
const eased = 1 - Math.pow(1 - progress, 4);
const current = Math.floor(eased * target);
el.textContent = current.toLocaleString() + suffix;
if (progress < 1) {
requestAnimationFrame(step);
} else {
el.textContent = target.toLocaleString() + suffix;
}
};
requestAnimationFrame(step);
}
// ===== NAV SCROLL EFFECT =====
function initNavScroll() {
const mainNav = document.getElementById('mainNav');
if (!mainNav) return;
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
mainNav.classList.add('glass', 'nav-scrolled');
} else {
mainNav.classList.remove('glass', 'nav-scrolled');
}
});
}
// ===== MOBILE MENU =====
function initMobileMenu() {
const toggle = document.getElementById('mobileMenuToggle');
const menu = document.getElementById('mobileMenu');
const close = document.getElementById('mobileMenuClose');
const overlay = document.getElementById('mobileMenuOverlay');
if (!toggle || !menu) return;
function openMenu() {
menu.classList.add('open');
if (overlay) overlay.classList.remove('hidden');
document.body.style.overflow = 'hidden';
}
function closeMenu() {
menu.classList.remove('open');
if (overlay) overlay.classList.add('hidden');
document.body.style.overflow = '';
}
toggle.addEventListener('click', openMenu);
if (close) close.addEventListener('click', closeMenu);
if (overlay) overlay.addEventListener('click', closeMenu);
// Close on link click
menu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', closeMenu);
});
}
// ===== SMOOTH SCROLL OFFSET =====
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offset = 80;
const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - offset;
window.scrollTo({ top: targetPosition, behavior: 'smooth' });
}
});
});
}
// ===== TOAST SYSTEM =====
function showToast(message, type = 'success') {
// Remove existing toast
const existingToast = document.getElementById('toast');
if (existingToast) existingToast.remove();
const iconMap = { success: 'check-circle', error: 'alert-circle', info: 'info' };
const colorMap = { success: 'text-green-400', error: 'text-red-400', info: 'text-blue-400' };
const toast = document.createElement('div');
toast.id = 'toast';
toast.className = 'fixed bottom-6 right-6 z-[60] flex';
toast.innerHTML = `
<div class="glass-heavy rounded-2xl px-6 py-4 flex items-center gap-3 shadow-2xl animate-scale-in">
<i data-lucide="${iconMap[type] || 'check-circle'}" class="w-5 h-5 ${colorMap[type] || 'text-green-400'}"></i>
<span class="text-sm font-semibold text-white">${message}</span>
</div>
`;
document.body.appendChild(toast);
initIcons();
setTimeout(() => {
toast.remove();
}, 3000);
}
// ===== FAQ ACCORDION =====
function initFAQ() {
document.querySelectorAll('.faq-item').forEach(item => {
const btn = item.querySelector('.faq-toggle');
if (!btn) return;
btn.addEventListener('click', () => {
const isOpen = item.classList.contains('open');
// Close all
document.querySelectorAll('.faq-item.open').forEach(openItem => {
openItem.classList.remove('open');
const answer = openItem.querySelector('.faq-answer');
if (answer) answer.style.maxHeight = '0';
});
// Open clicked
if (!isOpen) {
item.classList.add('open');
const answer = item.querySelector('.faq-answer');
if (answer) answer.style.maxHeight = answer.scrollHeight + 'px';
}
});
});
}
// ===== UTILITY =====
function delay(ms) { return new Promise(r => setTimeout(r, ms)); }
// ===== INIT ALL =====
document.addEventListener('DOMContentLoaded', () => {
initIcons();
initCursorGlow();
initScrollReveal();
initCounters();
initNavScroll();
initMobileMenu();
initSmoothScroll();
initFAQ();
// Info Modal
const infoBtn = document.getElementById('themeInfoBtn');
if (infoBtn) {
infoBtn.addEventListener('click', () => {
const modal = document.getElementById('infoModal');
if (modal) {
modal.classList.remove('hidden');
modal.classList.add('flex');
initIcons();
}
});
}
// Close modal
document.querySelectorAll('[data-close-modal]').forEach(btn => {
btn.addEventListener('click', () => {
const modal = btn.closest('[data-modal]');
if (modal) {
modal.classList.add('hidden');
modal.classList.remove('flex');
}
});
});
document.querySelectorAll('[data-modal]').forEach(modal => {
modal.addEventListener('click', (e) => {
if (e.target === modal) {
modal.classList.add('hidden');
modal.classList.remove('flex');
}
});
});
// Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
document.querySelectorAll('[data-modal]').forEach(modal => {
if (!modal.classList.contains('hidden')) {
modal.classList.add('hidden');
modal.classList.remove('flex');
}
});
}
});
}); |