1(function () { 2 function attach(form) { 3 if (form.dataset.cfBound) return; 4 form.dataset.cfBound = '1'; 5 6 var url = form.dataset.countUrl || '/local/ajax/catalog_count.php'; 7 var section = form.dataset.section || ''; 8 var countEl = form.querySelector('[data-cf-count]'); 9 var timer; 10 11 function buildParams() { 12 var p = new URLSearchParams(); 13 form.querySelectorAll('input[type="checkbox"]').forEach(function (cb) { 14 if (cb.checked && cb.name) p.append(cb.name, cb.value); 15 }); 16 if (section) p.set('section', section); 17 return p; 18 } 19 20 function refresh() { 21 if (countEl) countEl.classList.add('is-loading'); 22 fetch(url + '?' + buildParams().toString(), { headers: { 'X-Requested-With': 'fetch' } }) 23 .then(function (r) { return r.json(); }) 24 .then(function (d) { 25 if (countEl) { 26 countEl.textContent = (d && typeof d.count === 'number') ? plural(d.count) : ''; 27 countEl.classList.remove('is-loading'); 28 } 29 }) 30 .catch(function () { if (countEl) countEl.classList.remove('is-loading'); }); 31 } 32 33 var resetBtn = form.querySelector('[data-cf-reset]'); 34 if (resetBtn) { 35 resetBtn.addEventListener('click', function (e) { 36 e.preventDefault(); 37 form.querySelectorAll('input[type="checkbox"]').forEach(function (cb) { cb.checked = false; }); 38 if (location.search) { location.href = location.pathname; return; } 39 refresh(); 40 }); 41 } 42 43 form.addEventListener('change', function (e) { 44 if (e.target.matches('input[type="checkbox"]')) { 45 clearTimeout(timer); 46 timer = setTimeout(refresh, 120); 47 } 48 }); 49 50 refresh(); 51 } 52 53 function plural(n) { 54 var a = Math.abs(n) % 100, b = a % 10, w; 55 if (a > 10 && a < 20) w = 'ÑоваÑов'; 56 else if (b > 1 && b < 5) w = 'ÑоваÑа'; 57 else if (b === 1) w = 'ÑоваÑ'; 58 else w = 'ÑоваÑов'; 59 return n + ' ' + w; 60 } 61 62 function boot() { 63 document.querySelectorAll('form.catalog-filter, form#catalog-filter').forEach(attach); 64 } 65 66 if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot); 67 else boot(); 68})();
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.