PageSourceSearch

https://kroner.pro/local/templates/main/components/bitrix/sale.bas…/catalog/script.js?177868324612192

js kroner.pro collected 2026-10-06 08:59:01 UTC 12,192 bytes, 439 lines download raw bytes

1'use strict';
2
3function BitrixSmallCart() { }
4
5BitrixSmallCart.prototype = {
6
7	activate: function () {
8		this.cartElement = BX(this.cartId);
9		this.fixedPosition = this.arParams.POSITION_FIXED == 'Y';
10		if (this.fixedPosition) {
11			this.cartClosed = true;
12			this.maxHeight = false;
13			this.itemRemoved = false;
14			this.verticalPosition = this.arParams.POSITION_VERTICAL;
15			this.horizontalPosition = this.arParams.POSITION_HORIZONTAL;
16			this.topPanelElement = BX("bx-panel");
17
18			this.fixAfterRender(); // TODO onready
19			this.fixAfterRenderClosure = this.closure('fixAfterRender');
20
21			var fixCartClosure = this.closure('fixCart');
22			this.fixCartClosure = fixCartClosure;
23
24			if (this.topPanelElement && this.verticalPosition == 'top')
25				BX.addCustomEvent(window, 'onTopPanelCollapse', fixCartClosure);
26
27			var resizeTimer = null;
28			BX.bind(window, 'resize', function () {
29				clearTimeout(resizeTimer);
30				resizeTimer = setTimeout(fixCartClosure, 200);
31			});
32		}
33		this.setCartBodyClosure = this.closure('setCartBody');
34		BX.addCustomEvent(window, 'OnBasketChange', this.closure('refreshCart', {}));
35	},
36
37	fixAfterRender: function () {
38		this.statusElement = BX(this.cartId + 'status');
39		if (this.statusElement) {
40			if (this.cartClosed)
41				this.statusElement.innerHTML = this.openMessage;
42			else
43				this.statusElement.innerHTML = this.closeMessage;
44		}
45		this.productsElement = BX(this.cartId + 'products');
46		this.fixCart();
47	},
48
49	closure: function (fname, data) {
50		var obj = this;
51		return data
52			? function () { obj[fname](data) }
53			: function (arg1) { obj[fname](arg1) };
54	},
55	changeQty: function (itemId, action, value) {
56
57		var self = this;
58		var currentInput = document.querySelector(`.js-quantity_input-${itemId}`);
59
60
61		if (!currentInput) return;
62
63		var currentQuantity = parseInt(currentInput.value);
64		var newQuantity = currentQuantity;
65
66		if (action === 'plus') {
67			newQuantity = currentQuantity + 1;
68		} else if (action === 'minus') {
69			newQuantity = currentQuantity - 1;
70			if (newQuantity < 1) newQuantity = 1;
71		} else if (action === 'set') {
72			newQuantity = parseInt(value);
73			if (isNaN(newQuantity) || newQuantity < 1) newQuantity = 1;
74		}
75		var items = {};
76		items[itemId] = newQuantity;
77		// Мгновенно обновляем инпут
78		currentInput.value = newQuantity;
79
80		// Отправляем AJAX запрос
81		BX.ajax({
82			url: '/local/ajax/basket.php',
83			method: 'POST',
84			dataType: 'html',
85			data: {
86				sessid: BX.bitrix_sessid(),
87				action: "quantity",
88				parametrs: {
89					ITEMS: items  // Используем правильно сформированный объект
90				},
91				templateName: self.templateName,
92				arParams: self.arParams
93			},
94			onsuccess: function (response) {
95				this.setCartBodyClosure;
96			},
97			onfailure: function () {
98				// Если ошибка - возвращаем старое значение
99				currentInput.value = currentQuantity;
100			}
101		});
102
103		// Триггерим событие обновления корзины
104		BX.onCustomEvent('OnBasketChange');
105	},
106	toggleOpenCloseCart: function () {
107		if (this.cartClosed) {
108			BX.removeClass(this.cartElement, 'bx-closed');
109			BX.addClass(this.cartElement, 'bx-opener');
110			this.statusElement.innerHTML = this.closeMessage;
111			this.cartClosed = false;
112			this.fixCart();
113		}
114		else // Opened
115		{
116			BX.addClass(this.cartElement, 'bx-closed');
117			BX.removeClass(this.cartElement, 'bx-opener');
118			BX.removeClass(this.cartElement, 'bx-max-height');
119			this.statusElement.innerHTML = this.openMessage;
120			this.cartClosed = true;
121			var itemList = this.cartElement.querySelector("[data-role='basket-item-list']");
122			if (itemList)
123				itemList.style.top = "auto";
124		}
125		setTimeout(this.fixCartClosure, 100);
126	},
127
128	setVerticalCenter: function (windowHeight) {
129		var top = windowHeight / 2 - (this.cartElement.offsetHeight / 2);
130		if (top < 5)
131			top = 5;
132		this.cartElement.style.top = top + 'px';
133
134	},
135
136	fixCart: function () {
137		// set horizontal center
138		if (this.horizontalPosition == 'hcenter') {
139			var windowWidth = 'innerWidth' in window
140				? window.innerWidth
141				: document.documentElement.offsetWidth;
142			var left = windowWidth / 2 - (this.cartElement.offsetWidth / 2);
143			if (left < 5)
144				left = 5;
145			this.cartElement.style.left = left + 'px';
146		}
147
148		var windowHeight = 'innerHeight' in window
149			? window.innerHeight
150			: document.documentElement.offsetHeight;
151
152		// set vertical position
153		switch (this.verticalPosition) {
154			case 'top':
155				if (this.topPanelElement)
156					this.cartElement.style.top = this.topPanelElement.offsetHeight + 5 + 'px';
157				break;
158			case 'vcenter':
159				this.setVerticalCenter(windowHeight);
160				break;
161		}
162
163		// toggle max height
164		if (this.productsElement) {
165			var itemList = this.cartElement.querySelector("[data-role='basket-item-list']");
166			if (this.cartClosed) {
167				if (this.maxHeight) {
168					BX.removeClass(this.cartElement, 'bx-max-height');
169					if (itemList)
170						itemList.style.top = "auto";
171					this.maxHeight = false;
172				}
173			}
174			else // Opened
175			{
176				if (this.maxHeight) {
177					if (this.productsElement.scrollHeight == this.productsElement.clientHeight) {
178						BX.removeClass(this.cartElement, 'bx-max-height');
179						if (itemList)
180							itemList.style.top = "auto";
181						this.maxHeight = false;
182					}
183				}
184				else {
185					if (this.verticalPosition == 'top' || this.verticalPosition == 'vcenter') {
186						if (this.cartElement.offsetTop + this.cartElement.offsetHeight >= windowHeight) {
187							BX.addClass(this.cartElement, 'bx-max-height');
188							if (itemList)
189								itemList.style.top = 82 + "px";
190							this.maxHeight = true;
191						}
192					}
193					else {
194						if (this.cartElement.offsetHeight >= windowHeight) {
195							BX.addClass(this.cartElement, 'bx-max-height');
196							if (itemList)
197								itemList.style.top = 82 + "px";
198							this.maxHeight = true;
199						}
200					}
201				}
202			}
203
204			if (this.verticalPosition == 'vcenter')
205				this.setVerticalCenter(windowHeight);
206		}
207	},
208
209	refreshCart: function (data) {
210		if (this.itemRemoved) {
211			this.itemRemoved = false;
212			return;
213		}
214		data.sessid = BX.bitrix_sessid();
215		data.siteId = this.siteId;
216		data.templateName = this.templateName;
217		data.arParams = this.arParams;
218		BX.ajax({
219			url: this.ajaxPath,
220			method: 'POST',
221			dataType: 'html',
222			data: data,
223			onsuccess: this.setCartBodyClosure
224		});
225	},
226
227	setCartBody: function (result) {
228		if (this.cartElement) {
229
230			var oldList = this.cartElement.querySelector('.js-cart-items');
231			var scroll = oldList ? oldList.scrollTop : 0;
232
233			this.cartElement.innerHTML = result.replace(/#CURRENT_URL#/g, this.currentUrl);
234
235			var newList = this.cartElement.querySelector('.js-cart-items');
236			if (newList && scroll > 0) {
237
238
239				newList.scrollTop = scroll;
240
241			}
242		}
243		if (this.fixedPosition) {
244			setTimeout(this.fixAfterRenderClosure, 100);
245		}
246	},
247
248	removeItemFromCart: function (id, productId) {
249		this.refreshCart({ sbblRemoveItemFromCart: id });
250		this.itemRemoved = true;
251		BX.onCustomEvent('OnBasketChange');
252		setTimeout(() => {
253			const buttons = document.querySelectorAll(`[data-buy="${productId}"]`);
254
255			buttons.forEach(button => {
256				button.innerHTML = "В корзину";
257
258			});
259			var BasketCount = parseInt($('#BasketCount').html()) - 1;
260			if (BasketCount === 0) {
261				$('#BasketCount').css("display", "none");
262			}
263			$('#BasketCount').html(BasketCount);
264
265			let items = document.querySelectorAll(".favorBasket");
266
267			if (items.length <= 0) {
268				let BasketContainer = document.querySelector(".js-cart-items");
269				BasketContainer.classList.add("basket-empty");
270			}
271		}, 400);
272
273	},
274	Favorite: function (element) {
275		var favorID = element.dataset.item
276
277		if (element.classList.contains("_active")) {
278			var doAction = 'delete';
279		} else {
280			var doAction = 'add';
281
282		}
283		this.addFavorite(favorID, doAction, element);
284	},
285	addFavorite: function (id, action, element) {
286		$.ajax({
287			url: '/local/ajax/favorites.php', // URL отправки запроса
288			type: "post",
289			dataType: "json",
290			data: { id: id, action: action },
291			success: function (response) {
292				let result = response.text;
293
294				if (result == 1) { // Если всё хорошо, то выполняем действия, которые показывают, что данные отправлены
295					element.classList.add("_active");
296					var wishCount = parseInt($('#favoriteCount').html()) + 1;
297					if (wishCount > 0) {
298						$('#favoriteCount').css("display", "block");
299					}
300					$('#favoriteCount').html(wishCount); // Визуально меняем количество у иконки
301				}
302				if (result == 2) {
303					element.classList.remove("_active");
304					var wishCount = parseInt($('#favoriteCount').html()) - 1;
305					if (wishCount === 0) {
306						$('#favoriteCount').css("display", "none");
307						$('#favoriteCount').html(wishCount);
308
309					}
310					else {
311						$('#favoriteCount').html(wishCount);
312					}
313
314				}
315			},
316			error: function (jqXHR, textStatus, errorThrown) {
317				console.log('Error: ' + errorThrown);
318			}
319		});
320	},
321	changeQuantity: function (items) {
322		var to_data = {
323			sessid: BX.bitrix_sessid(),
324			action: "quantity",
325			parametrs: {
326				ITEMS: items
327			},
328			templateName: this.templateName,
329			arParams: this.arParams,
330		};
331
332		BX.ajax({
333			url: '/local/ajax/basket.php',
334			method: 'POST',
335			dataType: 'html',
336			data: to_data,
337			onsuccess: this.setCartBodyClosure
338		})
339	},
340	refreshCartData: function () {
341		var to_data = {
342			sessid: BX.bitrix_sessid(),
343			action: "refresh",
344			templateName: this.templateName,
345			arParams: this.arParams,
346		};
347
348		BX.ajax({
349			url: '/local/ajax/basket.php',
350			method: 'POST',
351			dataType: 'html',
352			data: to_data,
353			onsuccess: this.setCartBodyClosure
354		})
355	}
356}
356;
357addEventListener("DOMContentLoaded", (event) => {
358	const doc = document;
359	doc.addEventListener("click", (e) => {
360		if (e.target && e.target.classList.contains("jsQuantityMinus")) {
361			let input = e.target.closest('.js-quantity_container').querySelector('.jsQuantityBasket');
362			if (input) {
363				input.value--;
364				input.dispatchEvent(new Event('change', { bubbles: true })); // Инициация события изменения значения
365			}
366		}
367	});
368
369	doc.addEventListener("click", (e) => {
370		if (e.target && e.target.classList.contains("jsQuantityPlus")) {
371			let input = e.target.closest('.js-quantity_container').querySelector('.jsQuantityBasket');
372
373			if (input) {
374				input.value++;
375				// if(parseInt(input.value)>parseInt(input.dataset.max)){
376				// 	input.value=input.dataset.max;
377				// 	return;
378				// }
379				input.dispatchEvent(new Event('change', { bubbles: true }));
380			}
381		}
382	});
383
384	doc.addEventListener("change", (e) => {
385		if (e.target && e.target.classList.contains("jsQuantityBasket")) {
386			let node = e.target;
387			let id = node.closest('.js-quantity_container').dataset.item;
388			let cart = node.closest('.js-cart-items').id;
389
390			// if(parseInt(node.value)>parseInt(node.dataset.max)){
391			// 	node.value=node.dataset.max;
392			// 	return;
393			// }
394
395			// Обновление количества через глобальный объект
396			window[cart].changeQuantity({ [id]: node.value });
397		}
398	});
399	doc.addEventListener("click", (e) => {
400
401		if (e.target && (e.target.parentElement.classList.contains("simple-basketaddButton") || e.target.classList.contains("simple-basketaddButton"))) {
402			let cart = document.querySelector('.js-cart-items').id;
403			setTimeout(() => {
404				window[cart].refreshCartData();
405				let basket = document.querySelector(".basket-empty");
406				if (basket) {
407					basket.classList.remove("basket-empty");
408				}
409
410			}, "200");
411
412
413		}
414
415		if (e.target && e.target.classList.contains("basket-add")) {
416			let cart = document.querySelector('.js-cart-items').id;
417			setTimeout(() => {
418				window[cart].refreshCartData();
419				let basket = document.querySelector(".basket-empty");
420				if (basket) {
421					basket.classList.remove("basket-empty");
422				}
423
424			}, "200");
425
426
427		}
428	});
429	let items = document.querySelectorAll(".basket-item");
430
431	if (items.length <= 0) {
432		let BasketContainer = document.querySelector(".js-cart-items");
433		BasketContainer.classList.add("basket-empty");
434	}
435
436
437
438});
439

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.