1/* 2 * Script público de Nuglas Contador 3 * Pide el contador vÃa REST API (para saltar el caché) y lo anima. 4 */ 5document.addEventListener('DOMContentLoaded', function () { 6 7 // Busca todos los contadores en la página 8 const counters = document.querySelectorAll('.nuglas-animated-counter'); 9 10 if (counters.length === 0) { 11 return; // No hay contadores en esta página, no hacer nada. 12 } 13 14 // Llama a la API de WordPress que creamos en el plugin 15 // 'nuglasCounter' es un objeto que pasamos desde PHP (ver contador.php) 16 fetch(nuglasCounter.rest_url) 17 .then(response => response.json()) 18 .then(data => { 19 const targetCount = parseInt(data.count, 10); 20 21 // Anima cada contador que encuentre 22 counters.forEach(counter => { 23 animateValue(counter, 0, targetCount, 2000); // Anima de 0 al total en 2000ms (2 seg) 24 }); 25 }) 26 .catch(error => { 27 console.error('Error al cargar el contador:', error); 28 // Si falla, al menos muestra el número sin animar 29 counters.forEach(counter => counter.innerText = 'Error'); 30 }); 31 32 /** 33 * Función que anima un número de 'start' a 'end' durante 'duration' 34 */ 35 function animateValue(element, start, end, duration) { 36 let startTimestamp = null; 37 38 const step = (timestamp) => { 39 if (!startTimestamp) startTimestamp = timestamp; 40 41 const progress = Math.min((timestamp - startTimestamp) / duration, 1); 42 const currentValue = Math.floor(progress * (end - start) + start); 43 44 // Usa el formateador de números local (ej. "1,250" en lugar de "1250") 45 element.innerText = new Intl.NumberFormat().format(currentValue); 46 47 // Si no hemos terminado, sigue animando 48 if (progress < 1) { 49 window.requestAnimationFrame(step); 50 } 51 }; 52 53 window.requestAnimationFrame(step); 54 } 55});
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.