PageSourceSearch

https://w4u.in/assets/js/bw-cart-count.js?v=1790462261

js w4u.in collected 2026-10-01 15:55:36 UTC 1,971 bytes, 66 lines download raw bytes

1/**
2 * Safe cart badge updater — accepts plain number or legacy HTML fragment.
3 */
4(function (window, $) {
5  if (!$) {
6    return;
7  }
8  var prevUpdate = window.bwUpdateCartCount;
9
10  window.bwUpdateCartCount = function (data) {
11    var n = 0;
12    if (typeof data === 'number') {
13      n = data;
14    } else if (data && typeof data === 'object' && data.count != null) {
15      n = parseInt(data.count, 10) || 0;
16    } else {
17      var raw = String(data == null ? '' : data).replace(/<[^>]*>/g, '').replace(/[^\d-]/g, '');
18      n = parseInt(raw, 10);
19      if (isNaN(n) || n < 0) {
20        n = 0;
21      }
22    }
23
24    var $badges = $('#cart-count, .cart-count').filter(function () {
25      return this.id === 'cart-count' || $(this).closest('a#cart, .bw-widget-cart, .cartt, .h20-m-cart, .h16-m-cart').length;
26    });
27    if (!$badges.length) {
28      $badges = $('#cart-count');
29    }
30
31    $badges.each(function () {
32      var el = this;
33      // Unwrap nested legacy badges — use native remove to avoid appear.js $.fn.remove hooks
34      var nested = el.querySelectorAll('#cart-count, .cart-count');
35      for (var i = 0; i < nested.length; i++) {
36        if (nested[i].parentNode) nested[i].parentNode.removeChild(nested[i]);
37      }
38      el.textContent = String(n);
39      el.setAttribute('data-count', String(n));
40      if (n > 0) {
41        el.style.display = '';
42        el.classList.remove('is-empty');
43      } else {
44        el.classList.add('is-empty');
45      }
46    });
47
48    if (typeof prevUpdate === 'function') {
49      try { prevUpdate(n); } catch (err) {}
50    }
51    return n;
52  };
53
54  // On load: unwrap nested legacy badges and hide zero counts
55  $(function () {
56    $('#cart-count').each(function () {
57      var $el = $(this);
58      var nested = $el.find('#cart-count, .cart-count').last();
59      if (nested.length) {
60        bwUpdateCartCount(nested.text());
61        return;
62      }
63      bwUpdateCartCount($el.text());
64    });
65  });
66})(window, window.jQuery);

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.