Loading...

`.trim(); const iframe = document.createElement('iframe'); iframe.setAttribute('title', 'reCAPTCHA'); iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-popups'); iframe.style.width = '304px'; iframe.style.height = '90px'; iframe.style.border = '0'; iframe.style.overflow = 'hidden'; iframe.style.borderRadius = '12px'; iframe.srcdoc = html; mount.appendChild(iframe); } /* Abrir/cerrar modal */ function openLoginModal() { const modal = document.getElementById('loginModal'); if (!modal) return; modal.classList.remove('hidden'); modal.classList.add('flex'); modal.setAttribute('aria-modal', 'true'); modal.setAttribute('role', 'dialog'); mountRecaptchaIframe(); // ← aquí se monta el iframe con reCAPTCHA const firstInput = modal.querySelector('input[name="usuario"]'); if (firstInput) firstInput.focus(); } function closeLoginModal() { const modal = document.getElementById('loginModal'); if (!modal) return; modal.classList.add('hidden'); modal.removeAttribute('aria-modal'); modal.removeAttribute('role'); } window.openLoginModal = openLoginModal; /* Recibir token desde el iframe y colocarlo en el input hidden */ window.addEventListener('message', function(ev){ if (!ev || !ev.data || ev.data.type !== 'recaptcha') return; var inp = document.getElementById('g-recaptcha-response'); if (inp) inp.value = ev.data.token || ''; }); /* Botones / enlaces → abrir modal */ ['openLoginModalDesktop','openLoginModalMobile','openLoginModalMobileTop'].forEach(id => { const el = document.getElementById(id); if (!el) return; el.addEventListener('click', (e) => { e.preventDefault(); openLoginModal(); }); }); /* Cerrar modal: botón, click fuera, ESC */ const closeBtn = document.getElementById('closeLoginModal'); if (closeBtn) closeBtn.addEventListener('click', closeLoginModal); const loginModal = document.getElementById('loginModal'); if (loginModal) { loginModal.addEventListener('click', (e) => { if (e.target === loginModal) closeLoginModal(); }); } document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && loginModal && !loginModal.classList.contains('hidden')) closeLoginModal(); }); /* Interceptar cualquier del documento */ document.querySelectorAll('a[href="/login"], a[href^="/login?"]').forEach(a => { a.addEventListener('click', (e) => { e.preventDefault(); openLoginModal(); }); }); /* Auto-abrir modal si la URL es /login o ?showLogin=1 */ try { const url = new URL(window.location.href); if (url.pathname === '/login' || url.searchParams.has('showLogin')) { openLoginModal(); url.searchParams.delete('showLogin'); history.replaceState({}, '', (url.pathname === '/login' ? '/' : url.pathname) + (url.search ? url.search : '')); } } catch {} })(); Más vistas — Página 19 | SSNUD