1const { IntersectionObserver } = window; 2 3const SELECTOR = '.count-up'; 4 5function onDocumentReady() { 6 if (!IntersectionObserver) { 7 return; 8 } 9 10 const els = document.querySelectorAll(SELECTOR); 11 if (els.length === 0) { 12 return; 13 } 14 15 const observer = new IntersectionObserver( 16 entries => onObserveIntersection(entries, observer), 17 { 18 threshold: 0.5, 19 } 20 ); 21 22 [...els].forEach(el => initializeElement(el, observer)); 23} 24 25function initializeElement(el, observer) { 26 const text = el.textContent; 27 let countTo; 28 if (text.includes(",")) { 29 countTo = text.replace(/[+$]/g, ''); 30 } else { 31 countTo = parseFloat(text.replace(/[^0-9\.]/, '')); 32 } 33 34 if (!(text && countTo)) { 35 return; 36 } 37 38 const prefix = text.match(/^([^0-9]+)/)?.pop(); 39 if (prefix) { 40 el.dataset.prefix = text.match(/^([^0-9]+)/)?.pop(); 41 } 42 43 const suffix = text.match(/([^0-9]+)$/)?.pop(); 44 if (suffix) { 45 el.dataset.suffix = text.match(/([^0-9]+)$/)?.pop(); 46 } 47 48 el.dataset.countTo = countTo; 49 50 observer.observe(el); 51} 52 53function onObserveIntersection(entries, observer) { 54 entries.forEach(entry => { 55 if (entry.isIntersecting) { 56 observer.unobserve(entry.target); 57 onElementEnter(entry.target); 58 } 59 }); 60} 61 62function formatCount(n) { 63 return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',').trim(); 64} 65 66function formatCommaCount(n) { 67 return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '').trim(); 68} 69 70function getSignificantDigits(n) { 71 const splitNumber = n.toString().split('.'); 72 if (splitNumber.length == 2) { 73 return Math.pow(10, splitNumber[1].length); 74 } 75 76 return 1; 77} 78 79function onElementEnter(el) { 80 const countUp = { value: 0 }; 81 var { countTo, prefix, suffix } = el.dataset; 82 const pre = prefix || ''; 83 const suf = suffix || ''; 84 if (countTo.includes(",")) { 85 countTo = countTo.replace(/[^a-zA-Z0-9]/g, ''); 86 } 87 88 el.textContent =`${pre}${formatCount(countUp.value)}${suf}`; 89 90 anime({ 91 targets: countUp, 92 value: [0, countTo], 93 round: getSignificantDigits(countTo), 94 delay: 200, 95 easing: 'easeOutCubic', 96 update: () => { 97 if (el.dataset.countTo.includes(",")) { 98 el.textContent = `${pre}${formatCount(countUp.value)}${suf}`; 99 } else { 100 el.textContent = `${pre}${formatCommaCount(countUp.value)}${suf}`; 101 } 102 }, 103 }); 104} 105 106document.addEventListener('DOMContentLoaded', onDocumentReady);
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.