PageSourceSearch

https://pscontrol.ru/wa-data/public/shop/themes/easystart/js/products.js?v1.0.9.1.73

js pscontrol.ru collected 2026-09-24 11:56:55 UTC 9,777 bytes, 319 lines download raw bytes

1// Shop :: Products Class
2var Products = ( function($) {
3
4    Products = function(options) {
5        var that = this;
6
7        // DOM
8        that.$wrapper = options["$wrapper"];
9        that.$products = that.$wrapper.find(".product-item");
10        that.$sorting = that.$wrapper.find(".products-sorting");
11        that.$productList = that.$wrapper.find(".products__list");
12
13        // VARS
14        that.added_class = "is-added";
15        that.compare = ( options['compare'] || false );
16
17        // DYNAMIC VARS
18
19        // INIT
20        that.bindEvents();
21    };
22
23    Products.prototype.bindEvents = function() {
24        var that = this,
25            $wrapper = that.$wrapper;
26
27        $wrapper.on("submit", "form.add-to-cart", function(event) {
28            event.preventDefault();
29            that.onSubmitProduct( $(this) );
30        });
31
32        $wrapper.on("click", ".product-add__button", function(event) {
33            event.preventDefault();
34            that.onAddProduct( $(this) );
35        });
36
37        $wrapper.on("click", ".product-compare", function(event) {
38            event.preventDefault();
39            that.onCompareProduct( $(this) );
40        });
41
42        $wrapper.on("click", ".product-favorite", function(event) {
43            event.preventDefault();
44            that.onFavoriteProduct( $(this) );
45        });
46
47        $wrapper.on("click", ".products-layouts__list", function() {
48            that.onChangeView( $(this), true );
49            return false;
50        });
51
52        $wrapper.on("click", ".products-layouts__thumbs", function() {
53            that.onChangeView( $(this), false );
54            return false;
55        });
56
57        $wrapper.on("click", ".increase-volume", function () {
58            that.increaseQuantity( true, $(this) );
59        });
60
61        $wrapper.on("click", ".decrease-volume", function() {
62            that.increaseQuantity( false, $(this) );
63        });
64
65        $wrapper.find(".product-quantity__field").on("change", function() {
66            that.changeQuantity( $(this) );
67        });
68
69        $wrapper.on("click", ".product-preview", function(event) {
70            event.preventDefault();
71            that.onPreviewProduct( $(this) );
72        });
73    };
74
75    // SORTING
76    Products.prototype.onChangeView = function( $link, is_table ) {
77        var that = this,
78            $list = that.$productList,
79            active_class = "is-active",
80            table_class = "list-view",
81            thumbs_class = "thumbs-view",
82            is_active = $link.hasClass(active_class);
83
84        if (!is_active) {
85
86            if (is_table) {
87                $list
88                    .removeClass(thumbs_class)
89                    .addClass(table_class);
90
91                $.cookie('products__view', 'list-view', { expires: 30, path: "/"});
92
93            } else {
94                $list
95                    .removeClass(table_class)
96                    .addClass(thumbs_class);
97
98                $.cookie('products__view', 'thumbs-view', { expires: 30, path: "/"});
99            }
100
101            that.$sorting.find(".products-layouts ." + active_class).removeClass(active_class);
102            $link.addClass(active_class)
103
104        }
105    };
106
107    Products.prototype.onPreviewProduct = function($form) {
108        var that = this,
109            $product = $form.closest(".product-item"),
110            product_href = $form.data("url");
111
112            $.post(product_href, function( html ) {
113
114                $('body').append('<div class="loading-overlay"><div class="loader"></div></div>');
115
116                var dialog = new Dialog({
117                    html: html
118                });
119
120                var $dialog = dialog.$dialog;
121
122                $dialog.on("addedToCart", function() {
123                    that.maskProductAsAdded( $product );
124                });
125            });
126    };
127
128    // ADD PRODUCT
129    Products.prototype.onSubmitProduct = function($form) {
130        var that = this,
131            $product = $form.closest(".product-item"),
132            product_href = $form.data("url");
133
134        if (product_href) {
135            $.post(product_href, function( html ) {
136
137                $('body').append('<div class="loading-overlay"><div class="loader"></div></div>');
138
139                var dialog = new Dialog({
140                    html: html
141                });
142
143                var $dialog = dialog.$dialog;
144
145                $dialog.on("addedToCart", function() {
146                    that.maskProductAsAdded( $product );
147                });
148
149            });
150
151        } else {
152            $.post($form.attr('action') + '?html=1', $form.serialize(), function (response) {
153                that.maskProductAsAdded( $product );
154
155                // Update Cart at Header
156                if (response["data"]) {
157                    var count = response["data"]["count"],
158                        text = response["data"]["total"];
159
160                    if (text && count >= 0) {
161                        updateCartCounter({
162                            text: text,
163                            count: count
164                        });
165                    }
166                }
167
168            }, "json");
169        }
170    };
171
172    Products.prototype.onAddProduct = function( $button ) {
173        var that = this,
174            is_active = $button.hasClass(that.added_class);
175
176        if (!is_active) {
177            var $form = $button.closest(".product-item").find("form.add-to-cart");
178            var yandexCounter = $form.data('counter');
179            var yandexAdd = $form.data('add');
180
181            if (yandexCounter && yandexAdd) {
182              sendYandex(yandexCounter, yandexAdd);
183            }
184
185            $form.submit();
186        }
187    };
188
189    Products.prototype.maskProductAsAdded = function( $product ) {
190        var that = this,
191            $button = $product.find(".product-add__button"),
192            $overlay = $product.find(".product-overlay"),
193            added_text = $button.data("added-text");
194
195
196        $button
197            .addClass(that.added_class)
198            .val(added_text);
199
200        $overlay.addClass("is-visible");
201    };
202
203    Products.prototype.increaseQuantity = function( increase, $button ) {
204        var that = this,
205            $wrapper = $button.closest(".product-quantity"),
206            $quantity = $wrapper.find(".product-quantity__field"),
207            value = parseInt( $quantity.val() ),
208            new_value = 1;
209
210        if (value && value > 0) {
211            new_value = (increase) ? value + 1 : value - 1;
212        }
213
214        $quantity
215            .val(new_value)
216            .trigger("change");
217
218    };
219
220    Products.prototype.changeQuantity = function( $quantity ) {
221        var that = this,
222            input_max_data = parseInt( $quantity.data("max-quantity")),
223            max_val = ( isNaN(input_max_data) || input_max_data === 0 ) ? Infinity : input_max_data,
224            value = parseInt( $quantity.val() ),
225            new_value = 1;
226
227        if (value && value > 0) {
228            new_value = (value >= max_val) ? max_val : value;
229        }
230
231        $quantity.val(new_value);
232    };
233
234    // COMPARE
235
236    Products.prototype.onCompareProduct = function( $button ) {
237        var that = this,
238            active_class = "is-active",
239            $icon = $button.find(".product-compare__icon"),
240            product_id = $button.data("product"),
241            is_active = $button.hasClass(active_class),
242            is_disabled = ( $button.data("is_disabled") || false );
243
244        var compare = $.cookie('shop_compare'); // Product Id's Array @string
245        compare = (compare) ? compare.split(',') : [];
246
247        if (is_active) {
248            //
249            $button.removeClass(active_class);
250
251            //
252            var index = $.inArray( product_id + '', compare);
253            if (index != -1) {
254                compare.splice(index, 1)
255            }
256            if (compare.length > 0) {
257                $.cookie('shop_compare', compare.join(','), { expires: 30, path: '/'});
258            } else {
259                $.cookie('shop_compare', null, {path: '/'});
260            }
261
262        } else {
263            //
264            $button.addClass(active_class);
265
266            //
267            compare.push(product_id);
268            $.cookie('shop_compare', compare.join(','), { expires: 30, path: '/'});
269        }
270
271        var compare_url = that.compare["url"];
272        if (compare.length > 0) {
273            compare_url = compare_url.replace(/compare\/.*$/, 'compare/' + compare.join(',') + '/');
274        }
275
276        //compare_url
277        $(".shop-compare__counter").trigger("checkCompare");
278    };
279
280    Products.prototype.onFavoriteProduct = function( $button ) {
281        var that = this,
282            active_class = "is-active",
283            $icon = $button.find(".product-favorite__icon"),
284            product_id = $button.data("product"),
285            is_active = $button.hasClass(active_class);
286
287        var favorite = $.cookie('shop_favorite'); // Product Id's Array @string
288        favorite = (favorite) ? favorite.split(',') : [];
289
290        if (is_active) {
291            //
292            $button.removeClass(active_class);
293
294            //
295            var index = $.inArray( product_id + '', favorite);
296            if (index != -1) {
297                favorite.splice(index, 1)
298            }
299            if (favorite.length > 0) {
300                $.cookie('shop_favorite', favorite.join(','), { expires: 30, path: '/'});
301            } else {
302                $.cookie('shop_favorite', null, {path: '/'});
303            }
304
305        } else {
306            //
307            $button.addClass(active_class);
308
309            //
310            favorite.push(product_id);
311            $.cookie('shop_favorite', favorite.join(','), { expires: 30, path: '/'});
312        }
313
314        $(".shop-favorite__counter").trigger("checkFavorite");
315    };
316
317    return Products;
318
319})(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.