PageSourceSearch

https://www.bachersport.com/fileadmin/templates/elements/el-product-shop/el-product-shop.js?1730302473

js bachersport.com collected 2026-10-10 01:24:03 UTC 5,852 bytes, 208 lines download raw bytes

1/*========================================================*\
2|| el-product-shop
3\*========================================================*/
4
5(function () {
6  $(document).ready(function () {
7    /* cart site */
8    if ($(".product-cart").length) {
9      $("body").addClass("js-product-cart-site");
10    }
11  });
12
13  /*========================================================*\
14  || shop */
15
16  function setCartNotEmpty() {
17    localStorage.setItem("bh-product-shop-cartNotEmpty", "true");
18  }
19
20  function clearCart() {
21    Cart.clear();
22    localStorage.removeItem("bh-product-shop-cartNotEmpty");
23  }
24
25  $(document).ready(function () {
26
27    $("body")
28      .off("click", ".js-add-product-to-cart")
29      .on("click", ".js-add-product-to-cart", function (event) {
30        const product = $(this).closest("[data-product]");
31        Cart.change(product, 1);
32        setCartNotEmpty();
33      });
34
35    $("body")
36    .off("click", ".js-shopping-cart___item__remove-button")
37    .on("click", ".js-shopping-cart___item__remove-button", function (event) {
38      event.preventDefault();
39      const product = $(this).closest("[data-product]");
40      Cart.remove(product);
41      Cart.refresh();
42      // clearCart();
43    });
44
45    $("body")
46      .off("submit", ".product-cart")
47      .on("submit", ".product-cart", function () {
48        clearCart();
49      });
50
51    // if (!$(".js-product-cart-site").length && localStorage.getItem("bh-product-sh
51op-cartNotEmpty")) {
52    //   clearCart();
53    // }
54
55    Cart.init();
56
57    Cart.refresh();
58
59    $("body").trigger("cart-updated");
60  });
61
62  /*
63  || cart */
64
65  var Cart = {
66    items: {},
67
68    init: function () {
69      this.items = this.read();
70    },
71
72    refresh: function () {
73      $("[data-product]").each(function () {
74        var product = $(this);
75        var uid = Cart.getUid(product);
76        if (uid in Cart.items) {
77          Cart.change(product, Cart.items[uid].count);
78        }
79      });
80      this.refreshCart();
81    },
82
83    refreshCart: function () {
84      if ($(".product-cart").length) {
85        $(".product-cart__item:not(.product-cart__item--template)").remove();
86
87        if ($.isEmptyObject(this.items)) {
88          $(".product-cart").addClass("js-shopping-cart--empty");
89        } else {
90          $(".product-cart").removeClass("js-shopping-cart--empty");
91        }
92
93        $.each(this.items, function (index, product) {
94          var template = $(".product-cart__item--template").clone();
95          template.removeClass("product-cart__item--template").removeAttr("inert");
96          template.attr("data-product", product.uid);
97
98          const formNamePrefix = "tx_cooquickanfrage_anfrageform[data][produkt][" + product.uid + "]";
99
100          template
101            .find(".product-cart__item__input--name")
102            .attr("name", formNamePrefix + "[artikelname]")
103            .val(product.name);
104
105          if (product.price) {
106            if (product.isPriceFrom) {
107              const from = template.find(".js-product-cart__item__price--from").text();
108              template
109              .find(".product-cart__item__input--price")
110              .attr("name", formNamePrefix + "[preis]")
111              .val(from + product.price);
112            } else {
113              template.find(".js-product-cart__item__price--from").remove();
114              template
115              .find(".product-cart__item__input--price")
116              .attr("name", formNamePrefix + "[preis]")
117              .val(product.price);
118            }
119          } else {
120            template.find(".product-cart__item__input--price").remove();
121          }
122
123          if (product.img) {
124            template.find(".product-cart__item__header__image").css("background-image", "url('" + product.img + "')");
125          }
126
127          template.find(".product-cart__item__name").text(product.name);
128
129          if (product.price) {
130            template.find(".js-product-cart__item__price").text(product.price);
131          } else {
132            template.find(".js-product-cart__item__prices").remove();
133          }
134
135          $(".product-cart__items-wrapper").append(template);
136        });
137      }
138    },
139
140    read: function () {
141      try {
142        var result = localStorage.getItem("bh-product-shop");
143        return JSON.parse(result) || {};
144      } catch (exception) {
145        return {};
146      }
147    },
148
149    write: function () {
150      try {
151        localStorage.setItem("bh-product-shop", JSON.stringify(Cart.items));
152      } catch (exception) {}
153    },
154
155    clear: function () {
156      this.items = {};
157      this.write();
158    },
159
160    getUid: function (product) {
161      return product.attr("data-product");
162    },
163
164    getImg: function (product) {
165      return $.trim(product.find(".product-detail__image").first().attr("src")) || "";
166    },
167
168    getName: function (product) {
169      return $.trim(product.find(".product-detail__heading").text()) || "";
170    },
171
172    getPrice: function (product) {
173      return $.trim(product.find(".js-product-detail__price").text()) || "";
174    },
175
176    getIsPriceFrom: function (product) {
177      return product.find(".js-product-detail__price--from").length == 1 ? true : false;
178    },
179
180    remove: function (product) {
181      this.change(product, 0);
182    },
183
184    change: function (product, newValue) {
185      var uid = Cart.getUid(product);
186      if (newValue <= 0) {
187        delete Cart.items[uid];
188      } else {
189        if (uid in Cart.items) {
190          Cart.items[uid].count = newValue;
191        } else {
192          Cart.items[uid] = {
193            uid: uid,
194            count: newValue,
195            img: Cart.getImg(product),
196            name: Cart.getName(product),
197            price: Cart.getPrice(product),
198            isPriceFrom: Cart.getIsPriceFrom(product),
199          };
200        }
201      }
202      this.refreshCart();
203      $("body").trigger("cart-updated");
204      Cart.write();
205    },
206
207  };
208})();

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.