1(function (Drupal, once) { 2 function parseBasketCount(value) { 3 var count = parseInt(String(value || '').trim(), 10); 4 if (isNaN(count) || count < 0) { 5 return 0; 6 } 7 return count; 8 } 9 10 function syncBasketBadge(badge) { 11 var count = parseBasketCount(badge.textContent); 12 var isEmpty = count <= 0; 13 var lastCount = badge.dataset.basketCount; 14 15 if (lastCount === String(count)) { 16 return; 17 } 18 19 badge.dataset.basketCount = String(count); 20 badge.classList.toggle('is-empty', isEmpty); 21 badge.setAttribute('aria-hidden', isEmpty ? 'true' : 'false'); 22 } 23 24 function observeBasketBadge(badge) { 25 syncBasketBadge(badge); 26 27 if (typeof MutationObserver === 'undefined') { 28 return; 29 } 30 31 var scheduled = false; 32 var observer = new MutationObserver(function () { 33 if (scheduled) { 34 return; 35 } 36 scheduled = true; 37 requestAnimationFrame(function () { 38 scheduled = false; 39 syncBasketBadge(badge); 40 }); 41 }); 42 43 observer.observe(badge, { 44 childList: true, 45 characterData: true, 46 subtree: true 47 }); 48 } 49 50 Drupal.behaviors.spektrixBasketBadge = { 51 attach: function (context) { 52 once('spektrix-basket-badge', '.cart-link__badge[data-basket-item-count]', context).forEach(function (badge) { 53 observeBasketBadge(badge); 54 }); 55 } 56 }; 57})(Drupal, once);
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.