PageSourceSearch

https://www.cup4you.ru/bundle/product-cards.js?v=1783682549

js cup4you.ru collected 2026-09-29 22:48:18 UTC 9,642 bytes, 272 lines download raw bytes

1const AJAX_FAIL_MESSAGE = 'Извините, что-то пошло не так :(';
2const MODIFICATION_PREFS_PREFIX = 'cup4you:modification:';
3
4function getModificationPrefsStorageKey(productId) {
5    return MODIFICATION_PREFS_PREFIX + productId;
6}
7
8function saveModificationPrefs(productId, attrs) {
9    if (!productId) {
10        return;
11    }
12
13    try {
14        localStorage.setItem(getModificationPrefsStorageKey(productId), JSON.stringify(attrs));
15    } catch (e) {}
16}
17
18function loadModificationPrefs(productId) {
19    if (!productId) {
20        return null;
21    }
22
23    try {
24        var raw = localStorage.getItem(getModificationPrefsStorageKey(productId));
25        return raw ? JSON.parse(raw) : null;
26    } catch (e) {
27        return null;
28    }
29}
30
31function buildModificationQuery(attrs) {
32    var params = [];
33
34    ['color', 'type', 'size', 'softness'].forEach(function (attr) {
35        if (attrs[attr]) {
36            params.push(attr + '=' + encodeURIComponent(attrs[attr]));
37        }
38    });
39
40    return params.length ? '?' + params.join('&') : '';
41}
42
43function getModificationAttrsFromElement(element) {
44    var $element = $(element);
45
46    return {
47        color: $element.attr('data-color') || '',
48        type: $element.attr('data-type') || '',
49        size: $element.attr('data-size') || '',
50        softness: $element.attr('data-softness') || '',
51        modificationId: $element.attr('data-modification-id') || ''
52    };
53}
54
55function updateProductImage(container, fallbackUrl, webpUrl) {
56    var $container = $(container);
57
58    if (!$container.length || !fallbackUrl) {
59        return;
60    }
61
62    var $picture = $container.is('picture') ? $container : $container.closest('picture');
63
64    if (!$picture.length) {
65        $picture = $container.find('picture').first();
66    }
67
68    if ($picture.length) {
69        var $source = $picture.find('source');
70
71        if ($source.length && webpUrl) {
72            $source.attr('srcset', webpUrl);
73        } else if ($source.length) {
74            $source.remove();
75        }
76
77        $picture.find('img').attr('src', fallbackUrl);
78        return;
79    }
80
81    var $img = $container.is('img') ? $container : $container.find('img').first();
82
83    if ($img.length) {
84        $img.attr('src', fallbackUrl);
85        return;
86    }
87
88    if ($container.hasClass('prod-img')) {
89        $container.css('background-image', "url('" + fallbackUrl + "')");
90    }
91}
92
93function updateModificationLinks(productModification, attrs) {
94    var href = productModification.find('a.img-link').attr('href');
95
96    if (!href) {
97        return;
98    }
99
100    var baseUrl = href.split('?')[0];
101    var url = baseUrl + buildModificationQuery(attrs);
102
103    productModification.find('a.img-link, a.product-title').attr('href', url);
104}
105
106function persistModificationState(productModification) {
107    var productId = productModification.attr('data-product-id');
108    var attrs = getModificationAttrsFromElement(productModification);
109
110    saveModificationPrefs(productId, attrs);
111    updateModificationLinks(productModification, attrs);
112}
113
114$(document).on('click', '.js-modification a[href*="/catalog/"]', function () {
115    var productModification = $(this).closest('.js-modification');
116
117    if (!productModification.length) {
118        return;
119    }
120
121    persistModificationState(productModification);
122});
123
124$(document).on('click', '.js-add-to-cart, .js-add-to-cart-page', function () {
125    var button = $(this);
126    var id;
127    var url;
128
129    if (button.data('modification-id') === undefined) {
130        url = '/cart/inc-product-quan';
131        id = button.data('product-id');
132    } else {
133        url = '/cart/inc-modification-quan';
134        id = button.data('modification-id');
135    }
136
137    $.ajax({
138        url: url,
139        method: 'get',
140        data: {
141            id: id
142        },
143        success: function (data) {
144            updateCartCounter(data);
145            $('.card-ok, .card-ok-bg').css('display', 'block');
146
147            if (button.hasClass('js-add-to-cart-page')) {
148                button.replaceWith('<button disabled class="page-product-addcart js-add-to-cart-page" style="color: rgb(155, 242, 232);border: 1px solid rgb(155, 242, 232);background: white;"><i class="fal fa-check" style="margin-right: 10px;"></i>В корзине</button>');
149            } else {
150                button.replaceWith('<span class="product-span-inactive"><i class="fal fa-check"></i> В корзине</span>');
151            }
152        },
153        error: function () {
154            alert(AJAX_FAIL_MESSAGE);
155        }
156    });
157});
158
159$(document).on('click', '.card-ok i', function () {
160    $('.card-ok, .card-ok-bg').hide();
161});
162
163$(document).on('change', '.js-change-modification', function () {
164    var select = $(this);
165    var activeOption = select.find(':selected');
166    var productModification = select.parents('.js-modification');
167    var productId = productModification.attr('data-product-id');
168    var dataToFind = {
169        productId: productId
170    };
171
172    if (activeOption.attr('data-color') !== undefined) {
173        var dataToFindColor = activeOption.attr('data-color');
174        dataToFind.color = dataToFindColor;
175        productModification.attr('data-color', dataToFindColor);
176        dataToFind.mainAttr = 'color';
177    } else if (productModification.attr('data-color')) {
178        dataToFind.color = productModification.attr('data-color');
179    }
180
181    if (activeOption.attr('data-type') !== undefined) {
182        var dataToFindType = activeOption.attr('data-type');
183        dataToFind.type = dataToFindType;
184        productModification.attr('data-type', dataToFindType);
185        dataToFind.mainAttr = 'type';
186    } else if (productModification.attr('data-type')) {
187        dataToFind.type = productModification.attr('data-type');
188    }
189
190    if (activeOption.attr('data-size') !== undefined) {
191        var dataToFindSize = activeOption.attr('data-size');
192        dataToFind.size = dataToFindSize;
193        productModification.attr('data-size', dataToFindSize);
194        dataToFind.mainAttr = 'size';
195    } else if (productModification.attr('data-size')) {
196        dataToFind.size = productModification.attr('data-size');
197    }
198
199    if (activeOption.attr('data-softness') !== undefined) {
200        var dataToFindSoftness = activeOption.attr('data-softness');
201        dataToFind.softness = dataToFindSoftness;
202        productModification.attr('data-softness', dataToFindSoftness);
203        dataToFind.mainAttr = 'softness';
204    } else if (productModification.attr('data-softness')) {
205        dataToFind.softness = productModification.attr('data-softness');
206    }
207
208    $.ajax({
209        url: '/catalog/ajax/product-modification',
210        method: 'get',
211        contentType: 'application/json',
212        dataType: 'json',
213        data: dataToFind,
214        success: function (foundModification) {
215            if (foundModification.modificationId !== undefined) {
216                var modificationId = foundModification.modificationId;
217                var isModificationInCart = foundModification.isInCart === true;
218                var cartButtonWrapper = productModification.find('.product-item-price-cart');
219                var oneclickOrderWrapper = productModification.find('.oneclick-order-text-wrapper-catalog');
220
221                productModification.attr('data-modification-id', modificationId);
222
223                if (oneclickOrderWrapper !== undefined) {
224                    oneclickOrderWrapper.html('<span class="oneclick-order-js oneclick-order-text" data-product-modification-id="' + modificationId + '">Заказать в 1 клик</span>');
225                }
226
227                if (!isModificationInCart) {
228                    cartButtonWrapper.html('<span class="js-add-to-cart" data-product-id="' + productId + '" data-modification-id="' + modificationId + '">
228В корзину</span>');
229                } else {
230                    cartButtonWrapper.html('<span class="product-span-inactive"><i class="fal fa-check"></i> В корзине</span>');
231                }
232            }
233
234            if (foundModification.price !== undefined) {
235                productModification.find('.product-item-price-sum').text(foundModification.price + ' руб.');
236            }
237
238            if (foundModification.photo !== undefined) {
239                updateProductImage(
240                    productModification.find('.prod-img'),
241                    foundModification.photo,
242                    foundModification.photoWebp
243                );
244            }
245
246            if (foundModification.color !== undefined) {
247                productModification.find('.js-change-modification-color').val(foundModification.color);
248                productModification.attr('data-color', foundModification.color);
249            }
250
251            if (foundModification.type !== undefined) {
252                productModification.find('.js-change-modification-type').val(foundModification.type);
253                productModification.attr('data-type', foundModification.type);
254            }
255
256            if (foundModification.size !== undefined) {
257                productModification.find('.js-change-modification-size').val(foundModification.size);
258                productModification.attr('data-size', foundModification.size);
259            }
260
261            if (foundModification.softness !== undefined) {
262                productModification.find('.js-change-modification-softness').val(foundModification.softness);
263                productModification.attr('data-softness', foundModification.softness);
264            }
265
266            persistModificationState(productModification);
267        },
268        error: function () {
269            alert(AJAX_FAIL_MESSAGE);
270        }
271    });
272});

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.