// Odoo Expertos — Main JavaScript document.addEventListener('DOMContentLoaded', () => { /* === Mobile Nav Toggle === */ const toggle = document.getElementById('navToggle'); const links = document.getElementById('navLinks'); if (toggle && links) { toggle.addEventListener('click', () => { links.classList.toggle('nav__links--open'); toggle.setAttribute('aria-expanded', links.classList.contains('nav__links--open') ? 'true' : 'false' ); }); // Close on link click links.querySelectorAll('.nav__link, .nav__cta').forEach(link => { link.addEventListener('click', () => { links.classList.remove('nav__links--open'); toggle.setAttribute('aria-expanded', 'false'); }); }); } /* === Highlight current nav link === */ const currentPath = window.location.pathname; document.querySelectorAll('.nav__link').forEach(link => { const href = link.getAttribute('href'); if (href && currentPath.startsWith(href) && href !== '/') { link.classList.add('nav__link--active'); } else if (href === '/' && currentPath === '/') { link.classList.add('nav__link--active'); } }); /* === Smooth scroll for anchor links === */ document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', e => { const target = document.querySelector(anchor.getAttribute('href')); if (target) { e.preventDefault(); target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); /* === Lazy load images === */ if ('loading' in HTMLImageElement.prototype) { document.querySelectorAll('img[loading="lazy"]').forEach(img => { img.src = img.dataset.src || img.src; }); } /* === Copy code blocks === */ document.querySelectorAll('pre').forEach(block => { const btn = document.createElement('button'); btn.className = 'copy-btn'; btn.textContent = 'Copiar'; btn.setAttribute('aria-label', 'Copiar código'); Object.assign(btn.style, { position: 'absolute', top: '8px', right: '8px', padding: '4px 10px', fontSize: '0.75rem', background: 'var(--color-bg-card)', border: '1px solid var(--color-border)', borderRadius: '4px', color: 'var(--color-text-muted)', cursor: 'pointer', opacity: '0', transition: 'opacity 150ms ease' }); block.style.position = 'relative'; block.appendChild(btn); block.addEventListener('mouseenter', () => btn.style.opacity = '1'); block.addEventListener('mouseleave', () => btn.style.opacity = '0'); btn.addEventListener('click', async () => { const code = block.querySelector('code'); if (code) { await navigator.clipboard.writeText(code.textContent); btn.textContent = '✓ Copiado'; setTimeout(() => { btn.textContent = 'Copiar'; }, 2000); } }); }); });