PageSourceSearch

https://sklepwaneko.pl/modules/x13pricehistory/views/js/front-list.js

js sklepwaneko.pl collected 2026-10-02 23:58:54 UTC 4,029 bytes, 129 lines download raw bytes

1document.addEventListener("DOMContentLoaded", () => {
2  var x13PriceHistoryListPrices = (function () {
3    var data = {
4      productIDs: [],
5      loadingInProgress: false,
6      ajaxUrl: x13pricehistory_ajax_url,
7    };
8
9    var DOMStrings = {
10      priceHistoryListContainer:
11        ".product-miniature .x13pricehistory-product-list.x13pricehistory-product-list-ajaxed",
12    };
13
14    var DOMClasses = {
15      inProgress: "x13pricehistory-product-list-loading",
16      pricesLoaded: "x13pricehistory-product-list-loaded",
17    };
18
19    function setEvents() {
20      if (typeof prestashop !== "undefined") {
21        prestashop.on("updateProductList", function () {
22          setTimeout(function () {
23            addProductsIDs();
24          }, 100);
25        });
26      }
27    }
28
29    function getProductThumbnails() {
30      var $productListAttributes = $(DOMStrings.priceHistoryListContainer)
31        .not("." + DOMClasses.pricesLoaded + ", ." + DOMClasses.inProgress)
32        .addClass(DOMClasses.inProgress);
33
34      return $productListAttributes;
35    }
36
37    function addProductsIDs() {
38      var $productsList = getProductThumbnails(),
39        foundIds = {};
40
41      $productsList.each(function () {
42        var id = $(this).data("product");
43        foundIds[id] = true;
44      });
45
46      var IDsArray = Object.keys(foundIds);
47      var prevDataIDs = data.productIDs.splice(0);
48      data.productIDs = prevDataIDs.concat(IDsArray);
49
50      if (!data.loadingInProgress) {
51        loadProductsData(data.productIDs);
52      }
53    }
54    function getByProduct(dataProduct) {
55      loadProductsData([dataProduct]);
56    }
57
58    function loadProductsData(productsIds) {
59      if (productsIds.length === 0) {
60        return;
61      }
62
63      data.loadingInProgress = true;
64      $.get(
65        data.ajaxUrl,
66        { token: x13pricehistory_ajax_token, id_products: productsIds },
67        function (jsonData) {
68          if (jsonData) {
69            const products = JSON.parse(jsonData);
70            $.each(products, function (idProduct, element) {
71              var $productData = element;
72              var $priceHistoryListContainer = $(
73                '.x13pricehistory-product-list[data-product="' +
74                  idProduct +
75                  '"]'
76              );
77
78              $priceHistoryListContainer
79                .find(".x13pricehistory-product-list__omnibus-price")
80                .text($productData.lowest_price);
81              $priceHistoryListContainer
82                .find(".discount.discount-percentage")
83                .text($productData.real_discount_value);
84
85              $priceHistoryListContainer
86                .closest(DOMStrings.priceHistoryListContainer)
87                .addClass(DOMClasses.pricesLoaded);
88              $priceHistoryListContainer
89                .closest(DOMStrings.priceHistoryListContainer)
90                .removeClass(DOMClasses.inProgress);
91              $priceHistoryListContainer
92                .closest(DOMStrings.priceHistoryListContainer)
93                .find(".x13pricehistory-product-list__dummy")
94                .remove();
95            });
96
97            data.loadingInProgress = false;
98          }
99
100          $(DOMStrings.priceHistoryListContainer).removeClass(
101            DOMClasses.inProgress
102          );
103          $(DOMStrings.priceHistoryListContainer).addClass(
104            DOMClasses.pricesLoaded
105          );
106
107          // w innym module mam tutaj loader i usuwam go dopiero po załadowaniu danych, ale tutaj nie wiem czy to jest konieczne
108          // można pomyśleć bo inaczej będzie trochę skakania strony, ja daje min-width i taką animacje jak facebook :-)
109          $(".x13pricehistory-product-list__dummy").remove();
110        }
111      );
112    }
113
114    return {
115      getByProduct: function (dataProduct) {
116        getByProduct(dataProduct);
117      },
118      load: function () {
119        addProductsIDs();
120      },
121      init: function () {
122        setEvents();
123      },
124    };
125  })();
126
127  x13PriceHistoryListPrices.init();
128  x13PriceHistoryListPrices.load();
129});

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.