1/* âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ 2 Formulario "Avisadme" de interesados (seguridad/form_interesados.php) 3 4 - Carga Cloudflare Turnstile solo cuando alguien toca el formulario, 5 para no meter el script en todas las visitas. 6 - Turnstile va en modo "interaction-only": casi nadie ve nada; solo si 7 Cloudflare duda aparece la casilla de verificación. 8 - EnvÃa por POST a /recogida_correos_info y pinta el resultado. 9 10 ES5 a propósito: la web tiene visitantes con navegadores antiguos. 11 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */ 12(function () { 13 'use strict'; 14 15 if (window.RCInteresados) { return; } 16 window.RCInteresados = true; 17 18 var URL_TURNSTILE = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&onload=rcInteresadosTurnstileListo'; 19 var ESPERA_MAXIMA = 20000; 20 21 var formularios = []; 22 var turnstileCargando = false; 23 var turnstileListo = false; 24 25 function iniciar() { 26 var nodos = document.querySelectorAll('form.rc-int'); 27 for (var i = 0; i < nodos.length; i++) { preparar(nodos[i]); } 28 } 29 30 function preparar(form) { 31 if (form.rcPreparado) { return; } 32 form.rcPreparado = true; 33 34 var estado = { form: form, widget: null, token: '', alTenerToken: null }; 35 formularios.push(estado); 36 37 form.addEventListener('focusin', cargarTurnstile); 38 form.addEventListener('submit', function (evento) { 39 evento.preventDefault(); 40 enviar(estado); 41 }); 42 } 43 44 /* ââ Turnstile âââââââââââââââââââââââââââââââââââââââââââââââââââââ */ 45 46 function cargarTurnstile() { 47 if (turnstileCargando || turnstileListo) { return; } 48 turnstileCargando = true; 49 50 var script = document.createElement('script'); 51 script.src = URL_TURNSTILE; 52 script.async = true; 53 script.onerror = function () { 54 turnstileCargando = false; 55 for (var i = 0; i < formularios.length; i++) { 56 if (formularios[i].alTenerToken) { 57 formularios[i].alTenerToken = null; 58 ocupado(formularios[i], false); 59 mensaje(formularios[i], 'error', 'No se ha podido cargar la verificación antirrobots. Si usas un bloqueador de anuncios, desactÃvalo aquà y vuelve a intentarlo.'); 60 } 61 } 62 }; 63 document.head.appendChild(script); 64 } 65 66 window.rcInteresadosTurnstileListo = function () { 67 turnstileListo = true; 68 turnstileCargando = false; 69 for (var i = 0; i < formularios.length; i++) { pintarWidget(formularios[i]); } 70 }; 71 72 function pintarWidget(estado) { 73 if (estado.widget !== null || !window.turnstile) { return; } 74 var caja = estado.form.querySelector('.rc-int-verificacion'); 75 estado.widget = window.turnstile.render(caja, { 76 sitekey: estado.form.getAttribute('data-sitekey'), 77 theme: estado.form.className.indexOf('rc-int--oscuro') !== -1 ? 'dark' : 'light', 78 appearance: 'interaction-only', 79 action: 'interesados', 80 language: 'es', 81 callback: function (token) { 82 estado.token = token; 83 if (estado.alTenerToken) { 84 var seguir = estado.alTenerToken; 85 estado.alTenerToken = null; 86 seguir(); 87 } 88 }, 89 'expired-callback': function () { estado.token = ''; }, 90 'error-callback': function () { 91 estado.token = ''; 92 if (estado.alTenerToken) { 93 estado.alTenerToken = null; 94 ocupado(estado, false); 95 mensaje(estado, 'error', 'La verificación antirrobots ha fallado. Recarga la página e inténtalo de nuevo.'); 96 } 97 } 98 }); 99 } 100 101 function reiniciarWidget(estado) { 102 estado.token = ''; 103 if (window.turnstile && estado.widget !== null) { 104 try { window.turnstile.reset(estado.widget); } catch (e) { /* nada */ } 105 } 106 } 107 108 /* ââ EnvÃo âââââââââââââââââââââââââââââââââââââââââââââââââââââââââ */ 109 110 function enviar(estado) { 111 var form = estado.form; 112 var campo = form.querySelector('.rc-int-correo'); 113 var casilla = form.querySelector('input[name=acepto]'); 114 var correo = campo.value.replace(/^\s+|\s+$/g, ''); 115 116 if (correo.length > 100 || !/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(correo)) { 117 mensaje(estado, 'error', 'Escribe un correo electrónico válido.'); 118 campo.focus(); 119 return; 120 } 121 if (!casilla.checked) { 122 mensaje(estado, 'error', 'Para apuntarte tienes que aceptar la polÃtica de privacidad.'); 123 casilla.focus(); 124 return; 125 } 126 127 ocupado(estado, true); 128 mensaje(estado, 'info', 'Comprobando que no eres un robotâ¦'); 129 130 if (estado.token) { mandar(estado); return; } 131 132 var seguir = function () { mandar(estado); }; 133 estado.alTenerToken = seguir; 134 cargarTurnstile(); 135 if (turnstileListo) { pintarWidget(estado); } 136 137 setTimeout(function () { 138 if (estado.alTenerToken === seguir) { 139 estado.alTenerToken = null; 140 ocupado(estado, false); 141 mensaje(estado, 'error', 'La verificación está tardando. Si ves una casilla de verificación, márcala y vuelve a pulsar «Avisadme».'); 142 } 143 }, ESPERA_MAXIMA); 144 } 145 146 function mandar(estado) { 147 var form = estado.form; 148 var datos = new FormData(form); 149 datos.append('token', estado.token); 150 151 mensaje(estado, 'info', 'Enviandoâ¦'); 152 153 var peticion = new XMLHttpRequest(); 154 peticion.open('POST', form.getAttribute('action'), true); 155 peticion.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 156 peticion.timeout = 20000; 157 158 peticion.onload = function () { 159 var respuesta = null; 160 try { respuesta = JSON.parse(peticion.responseText); } catch (e) { /* nada */ } 161 162 if (respuesta && respuesta.ok) { 163 hecho(estado); 164 return; 165 } 166 ocupado(estado, false); 167 reiniciarWidget(estado); 168 mensaje(estado, 'error', (respuesta && respuesta.mensaje) ? respuesta.mensaje : 'No hemos podido guardar tu correo. Inténtalo de nuevo en unos minutos.'); 169 }; 170 peticion.onerror = peticion.ontimeout = function () { 171 ocupado(estado, false); 172 reiniciarWidget(estado); 173 mensaje(estado, 'error', 'Error de conexión. Comprueba tu conexión e inténtalo de nuevo.'); 174 }; 175 176 peticion.send(datos); 177 } 178 179 /* ââ Pintado âââââââââââââââââââââââââââââââââââââââââââââââââââââââ */ 180 181 function hecho(estado) { 182 var form = estado.form; 183 var ano = form.getAttribute('data-ano') || ''; 184 185 var caja = document.createElement('div'); 186 caja.className = 'rc-int-hecho'; 187 188 var icono = document.createElement('span'); 189 icono.className = 'rc-int-hecho-icono'; 190 icono.setAttribute('aria-hidden', 'true'); 191 icono.textContent = 'â'; 192 193 var texto = document.createElement('div'); 194 var titulo = document.createElement('strong'); 195 titulo.textContent = '¡Apuntado!'; 196 texto.appendChild(titulo); 197 texto.appendChild(document.createTextNode('Te avisaremos en cuanto abramos las inscripciones' + (ano ? ' de Rock Camp ' + ano : '') + '.')); 198 199 caja.appendChild(icono); 200 caja.appendChild(texto); 201 202 while (form.firstChild) { form.removeChild(form.firstChild); } 203 form.appendChild(caja); 204 caja.setAttribute('tabindex', '-1'); 205 caja.focus(); 206 } 207 208 function ocupado(estado, si) { 209 var boton = estado.form.querySelector('.rc-int-boton'); 210 if (boton) { 211 boton.disabled = si; 212 boton.textContent = si ? 'Un momentoâ¦' : 'Avisadme'; 213 } 214 } 215 216 function mensaje(estado, tipo, texto) { 217 var caja = estado.form.querySelector('.rc-int-mensaje'); 218 if (!caja) { return; } 219 caja.className = 'rc-int-mensaje es-' + tipo; 220 caja.textContent = texto; 221 } 222 223 if (document.readyState === 'loading') { 224 document.addEventListener('DOMContentLoaded', iniciar); 225 } else { 226 iniciar(); 227 } 228})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.