PageSourceSearch

https://powderlife.ru/local/templates/powderlife/components/bitrix/catalog.item/main/script.js

js powderlife.ru collected 2026-10-08 17:32:00 UTC 8,180 bytes, 245 lines download raw bytes

1(function (window) {
2    'use strict';
3
4    if (window.PWDLCatalogItem)
5        return;
6
7    window.PWDLCatalogItem = function (arParams) {
8        this.product = {
9            id: '0',
10            quantity: 0
11        }
12
13        this.isFavoritesPage = false
14
15        this.visual = {
16            'ID': '',
17            'FAVORITE_ID': ''
18        }
19
20        this.obProduct = null
21        this.obFavoriteButton = null
22        this.obCompareBtn = null
23        this.obBuyLink = null
24        this.obQuantity = null
25        this.obQuantityInput = null
26        this.obQuantityUp = null
27        this.obQuantityDown = null
28
29        this.addUrl = ''
30
31        this.errorCode = 0;
32        if (typeof arParams === 'object') {
33            this.product.id = arParams.PRODUCT.ID;
34            this.isFavoritesPage = arParams.IS_FAVORITES_PAGE
35            this.visual = arParams.VISUAL;
36
37            this.addUrl = arParams.ADD_URL.replace('#ID#', arParams.PRODUCT.ID)
38        }
39
40        if (this.errorCode === 0) {
41            BX.ready(BX.delegate(this.init, this));
42        }
43    }
44
45    window.PWDLCatalogItem.prototype = {
46        init: function () {
47            this.obProduct = BX(this.visual.ID)
48
49            this.obFavoriteButton = BX(this.visual.FAVORITE_BUTTON_ID)
50            this.obFavoriteButton && BX.bind(this.obFavoriteButton, 'click', BX.proxy(this.toggleFavorite, this))
51
52            this.obCompareBtn = BX(this.visual.COMPARE_BUTTON_ID)
53            this.obCompareBtn && BX.bind(this.obCompareBtn, 'click', BX.proxy(this.toggleCompare, this))
54
55            this.obBuyLink = BX(this.visual.BUY_LINK)
56            this.obBuyLink && BX.bind(this.obBuyLink, 'click', BX.proxy(this.add, this))
57
58            this.obQuantity = BX(this.visual.QUANTITY)
59
60            if (this.obQuantity) {
61                this.obQuantityInput = BX(this.visual.QUANTITY_INPUT)
62                this.obQuantityUp = BX(this.visual.QUANTITY_UP)
63                this.obQuantityDown = BX(this.visual.QUANTITY_DOWN)
64
65                this.obQuantityUp && BX.bind(this.obQuantityUp, 'click', BX.proxy(this.changeQuantityUp, this))
66                this.obQuantityDown && BX.bind(this.obQuantityDown, 'click', BX.proxy(this.changeQuantityDown, this))
67            }
68
69            if (window.userData.favorites.includes(this.product.id)) {
70                BX.addClass(this.obFavoriteButton, 'active')
71            }
72
73            this.checkFavorite()
74            this.checkCompare()
75            this.checkBasket()
76        },
77
78        checkBasket: function () {
79            if (window.userData.basketItems) {
80                if (window.userData.basketItems.hasOwnProperty(this.product.id)) {
81                    let basketItem = window.userData.basketItems[this.product.id]
82
83                    this.setQuantity(basketItem.quantity)
84                }
85            }
86        },
87
88        setQuantity: function (quantity) {
89            this.product.quantity = quantity
90
91            if (this.product.quantity > 0) {
92                this.obQuantityInput && BX.adjust(this.obQuantityInput, {attrs: {value: quantity}})
93                this.obBuyLink && BX.addClass(this.obBuyLink, 'disabled');
94            } else {
95                this.obBuyLink && BX.removeClass(this.obBuyLink, 'disabled');
96            }
97        },
98
99        changeQuantityUp: function () {
100            this.add()
101        },
102
103        changeQuantityDown: function () {
104            this.changeBasketQuantity(this.product.quantity - 1)
105        },
106
107        checkFavorite: function () {
108            if (window.userData.favorites.includes(this.product.id)) {
109                BX.addClass(this.obFavoriteButton, 'active')
110            } else {
111                if (this.isFavoritesPage) {
112                    BX.remove(this.obProduct)
113                } else {
114                    BX.removeClass(this.obFavoriteButton, 'active')
115                }
116            }
117        },
118
119        toggleFavorite: function () {
120            if (window.userData.id === 0) {
121                popupOpen('auth')
122                return
123            }
124
125            waitCheck()
126            let formData = new FormData()
127
128            formData.set('sessid', BX.bitrix_sessid())
129            formData.set('productID', this.product.id)
130
131            BX.ajax.runComponentAction('bem:products.favorites.widget', 'toggle', {
132                data: formData,
133                mode: 'class'
134            }).then(response => {
135                let data = response.data
136
137                window.userData = {...window.userData, favorites: data.items}
138                this.checkFavorite()
139                BX.onCustomEvent('onFavoritesChange', [data.items])
140                waitCheck('close')
141            }, response => {
142
143            })
144        },
145
146        toggleCompare: function () {
147            waitCheck()
148            let formData = new FormData()
149
150            formData.set('sessid', BX.bitrix_sessid())
151            formData.set('ajax_action', 'Y')
152
153            formData.set('id', this.product.id)
154
155            BX.ajax({
156                url: '/compare/',
157                data: {
158                    'ajax_action': 'Y',
159                    'action': window.userData.compareItems.includes(this.product.id) ? 'DELETE_FROM_COMPARE_LIST' : 'ADD_TO_COMPARE_LIST',
160                    'id': this.product.id
161                },
162                method: 'POST',
163                dataType: 'json',
164                processData: true,
165                onsuccess: response => {
166                    if (response.STATUS === 'OK') {
167                        console.log(response)
168                        if (response.COUNT > 0)
169                            window.userData.compareItems.push(response.ID)
170                        else {
171                            let index = window.userData.compareItems.indexOf(response.ID)
172                            if (index > -1) {
173                                window.userData.compareItems.splice(index, 1)
174                            }
175                        }
176
177                        this.checkCompare()
178                        BX.onCustomEvent('OnCompareChange', [window.userData.compareItems])
179                        waitCheck('close')
180                    }
181                },
182                onfailure: response => {
183
184                }
185            })
186        },
187
188        checkCompare: function () {
189            if (window.userData.compareItems) {
190                if (window.userData.compareItems.includes(this.product.id)) {
191                    BX.addClass(this.obCompareBtn, 'active')
192                } else {
193                    BX.removeClass(this.obCompareBtn, 'active')
194                }
195            }
196        },
197
198        add: function () {
199            waitCheck()
200            $(this.obQuantity).addClass('button-load')
201
202            let formData = new FormData()
203
204            formData.set('sessid', BX.bitrix_sessid())
205            formData.set('productID', this.product.id)
206
207            BX.ajax.runAction('powderlife:core.basket.add', {data: formData}).then(response => {
208                if (response.status === 'success') {
209                    BX.onCustomEvent('OnBasketChange')
210
211                    waitCheck('close')
212                    $(this.obQuantity).removeClass('button-load')
213
214                    this.setQuantity(response.data[this.product.id].quantity)
215                }
216            }, response => {
217                console.log(response)
218            })
219        },
220
221        changeBasketQuantity: function (quantity) {
222            waitCheck()
223            $(this.obQuantity).addClass('button-load')
224
225            let formData = new FormData()
226
227            formData.set('sessid', BX.bitrix_sessid())
228            formData.set('productID', this.product.id)
229            formData.set('quantity', quantity)
230
231            BX.ajax.runAction('bem:core.basket.change', {data: formData}).then(response => {
232                if (response.status === 'success') {
233                    BX.onCustomEvent('OnBasketChange')
234
235                    waitCheck('close')
236                    $(this.obQuantity).removeClass('button-load')
237
238                    this.setQuantity(quantity)
239                }
240            }, response => {
241                console.log(response)
242            })
243        }
244    }
245})(window)

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.