PageSourceSearch

https://kartridgesale.ru/bitrix/templates/elektro_flat/components/…/.default/script.js?170942137910346

js kartridgesale.ru collected 2026-10-05 03:15:31 UTC 10,346 bytes, 410 lines download raw bytes

1function updateBasketTable(basketItemId, res) {
2	//update product params after recalculation
3	if(!!res.BASKET_DATA) {
4		for(id in res.BASKET_DATA.GRID.ROWS) {
5			if(res.BASKET_DATA.GRID.ROWS.hasOwnProperty(id)) {
6				var item = res.BASKET_DATA.GRID.ROWS[id];				
7
8				if(BX("price_" + id))
9					BX("price_" + id).innerHTML = item.PRICE_FORMATED;
10
11				if(BX("old-price_" + id))
12					BX("old-price_" + id).innerHTML = (item.FULL_PRICE_FORMATED != item.PRICE_FORMATED) ? item.FULL_PRICE_FORMATED : '';				
13
14				if(BX("unit_" + id))
15					BX("unit_" + id).innerHTML = item.MEASURE_TEXT;				
16				
17				if(BX("cart-item-summa_" + id)) {
18					var itemSumCont,
19						itemSumOld,
20						itemSumCurr,
21						decimals;
22
23					itemSumCont = $(BX("cart-item-summa_" + id));
24
25					itemSumOld = itemSumCont.data("itemsum");					
26					itemSumCont.data("itemsum", (item.PRICE * item.QUANTITY));
27					itemSumCurr = itemSumCont.data("itemsum");
28
29					if(itemSumCurr != itemSumOld) {
30						decimals = itemSumCont.data("decimal");
31						if(itemSumCont.data("hide-zero") == "Y") {			
32							if(Math.abs(parseFloat(itemSumCurr).toFixed(decimals)) == Math.abs(parseFloat(itemSumCurr).toFixed(0))) {						
33								decimals = 0;								
34							}
35						}
36						var options = {
37							useEasing: false,
38							useGrouping: true,
39							separator: itemSumCont.data("separator"),
40							decimal: itemSumCont.data("dec-point")
41						}
42						var counter = new countUp("itemSumVal_" + id, itemSumOld, itemSumCurr, decimals, 0.5, options);
43						counter.start();
44					}
45				}
46
47				//if the quantity was set by user to 0 or was too much, we need to show corrected quantity value from ajax response
48				if(BX("QUANTITY_" + id)) {
49					BX("QUANTITY_" + id).value = item.QUANTITY;
50				}
51			}
52		}
53	}
54
55	//update coupon info
56	if(!!res.BASKET_DATA)
57		couponListUpdate(res.BASKET_DATA);
58
59	//update total basket values
60	if(!!res.BASKET_DATA) {
61		if(BX("cart-allsum")) {
62			var allSumCont,
63				allSumOld,
64				allSumCurr,
65				decimals;
66
67			allSumCont = $(BX("cart-allsum"));
68			
69			allSumOld = allSumCont.data("allsum");		
70			allSumCont.data("allsum", res["BASKET_DATA"]["allSum"]);
71			allSumCurr = allSumCont.data("allsum");
72
73			if(allSumCurr != allSumOld) {
74				decimals = allSumCont.data("decimal");
75				if(allSumCont.data("hide-zero") == "Y") {			
76					if(Math.abs(parseFloat(allSumCurr).toFixed(decimals)) == Math.abs(parseFloat(allSumCurr).toFixed(0))) {						
77						decimals = 0;										
78					}
79				}
80				var options = {
81					useEasing: false,
82					useGrouping: true,
83					separator: allSumCont.data("separator"),
84					decimal: allSumCont.data("dec-point")
85				}
86				var counter = new countUp("allSumVal", allSumOld, allSumCurr, decimals, 0.5, options);
87				counter.start();
88			}
89
90			BX.onCustomEvent("OnBasketChange");
91		}
92	}
93}
94
95function couponCreate(couponBlock, oneCoupon) {
96	var couponClass = 'disabled';
97
98	if(!BX.type.isElementNode(couponBlock))
99		return;
100	if(oneCoupon.JS_STATUS === 'BAD')
101		couponClass = 'bad';
102	else if(oneCoupon.JS_STATUS === 'APPLYED')
103		couponClass = 'good';
104
105	couponBlock.appendChild(BX.create(
106		'div',
107		{
108			props: {
109				className: 'bx_ordercart_coupon'
110			},
111			children: [				
112				BX.create(
113					'input',
114					{
115						props: {							
116							type: 'hidden',
117							value: oneCoupon.COUPON,
118							name: 'OLD_COUPON[]'
119						}						
120					}
121				),
122				BX.create(
123					'div',
124					{
125						props: {
126							className: 'old_coupon ' + couponClass
127						},
128						html: oneCoupon.COUPON + ' ' + oneCoupon.JS_CHECK_CODE
129					}
130				),
131				BX.create(
132					'span',
133					{
134						props: {
135							className: 'close ' + couponClass
136						},
137						attrs: {
138							'data-coupon': oneCoupon.COUPON
139						},
140						children: [
141							BX.create(
142								'i',
143								{
144									props: {
145										className: 'fa fa-times'
146									}
147								}
148							)
149						]
150					}
151				),
152				BX.create(
153					'div',
154					{
155						props: {
156							className: 'clr'
157						}						
158					}
159				)
160			]
161		}
162	));
163}
164
165function couponListUpdate(res) {
166	var couponBlock,		
167		fieldCoupon,
168		couponsCollection,
169		couponFound,
170		i,
171		j,
172		key;
173
174	if(!!res && typeof res !== 'object') {
175		return;
176	}
177
178	couponBlock = BX('cart-coupon');
179	if(!!couponBlock) {
180		if(!!res.COUPON_LIST && BX.type.isArray(res.COUPON_LIST)) {
181			fieldCoupon = BX('coupon');
182			if(!!fieldCoupon) {
183				fieldCoupon.value = '';
184			}
185			couponsCollection = BX.findChildren(couponBlock, { tagName: 'input', property: { name: 'OLD_COUPON[]' } }, true);			
186
187			if(!!couponsCollection) {
188				if(BX.type.isElementNode(couponsCollection)) {
189					couponsCollection = [couponsCollection];
190				}
191				for(i = 0; i < res.COUPON_LIST.length; i++) {
192					couponFound = false;
193					key = -1;
194					for(j = 0; j < couponsCollection.length; j++) {
195						if(couponsCollection[j].value === res.COUPON_LIST[i].COUPON) {
196							couponFound = true;
197							key = j;
198							couponsCollection[j].couponUpdate = true;
199							break;
200						}
201					}					
202					if(!couponFound)
203						couponCreate(couponBlock, res.COUPON_LIST[i]);
204				}
205				for(j = 0; j < couponsCollection.length; j++) {
206					if(typeof (couponsCollection[j].couponUpdate) === 'undefined' || !couponsCollection[j].couponUpdate) {
207						BX.remove(couponsCollection[j].parentNode);
208						couponsCollection[j] = null;
209					} else {
210						couponsCollection[j].couponUpdate = null;
211					}
212				}
213			} else {
214				for(i = 0; i < res.COUPON_LIST.length; i++) {
215					couponCreate(couponBlock, res.COUPON_LIST[i]);
216				}
217			}
218		}
219	}
220	couponBlock = null;
221}
222
223function checkOut() {
224	if(!!BX("coupon"))
225		BX("coupon").disabled = true;	
226	BX("basket_form").submit();	
227	return true;
228}
229
230function enterCoupon() {
231	var newCoupon = BX("coupon");
232	if(!!newCoupon && !!newCoupon.value)
233		recalcBasketAjax({"coupon" : newCoupon.value});
234}
235
236function updateQuantity(controlId, basketId, ratio, bUseFloatQuantity) {
237	var oldVal = BX(controlId).defaultValue,
238		newVal = parseFloat(BX(controlId).value) || 0,
239		bIsCorrectQuantityForRatio = false;
240
241	if(ratio === 0 || ratio == 1) {
242		bIsCorrectQuantityForRatio = true;
243	} else {
244		var newValInt = newVal * 10000,
245			ratioInt = ratio * 10000,
246			reminder = newValInt % ratioInt,
247			newValRound = parseInt(newVal);
248
249		if(reminder === 0) {
250			bIsCorrectQuantityForRatio = true;
251		}
252	}
253
254	var bIsQuantityFloat = false;
255
256	if(parseInt(newVal) != parseFloat(newVal)) {
257		bIsQuantityFloat = true;
258	}
259
260	newVal = (bUseFloatQuantity === false && bIsQuantityFloat === false) ? parseInt(newVal) : parseFloat(newVal).toFixed(2);
261
262	if(bIsCorrectQuantityForRatio) {
263		BX(controlId).defaultValue = newVal;		
264		
265		BX("QUANTITY_" + basketId).value = newVal;
266		
267		recalcBasketAjax({});
268	} else {
269		newVal = getCorrectRatioQuantity(newVal, ratio, bUseFloatQuantity);
270		
271		if(newVal != oldVal) {			
272			BX("QUANTITY_" + basketId).value = newVal;			
273			
274			recalcBasketAjax({});
275		} else {
276			BX(controlId).value = oldVal;
277		}
278	}
279}
280
281//used when quantity is changed by clicking on arrows
282function setQuantity(basketId, ratio, sign, bUseFloatQuantity) {
283	var curVal = parseFloat(BX("QUANTITY_" + basketId).value),
284		newVal;
285
286	newVal = (sign == 'up') ? curVal + ratio : curVal - ratio;
287
288	if(newVal < 0)
289		newVal = 0;
290
291	if(bUseFloatQuantity) {
292		newVal = newVal.toFixed(2);
293	}
294
295	if(ratio > 0 && newVal < ratio) {
296		newVal = ratio;
297	}
298
299	if(!bUseFloatQuantity && newVal != newVal.toFixed(2)) {
300		newVal = newVal.toFixed(2);
301	}
302
303	newVal = getCorrectRatioQuantity(newVal, ratio, bUseFloatQuantity);
304
305	BX("QUANTITY_" + basketId).value = newVal;
306	BX("QUANTITY_" + basketId).defaultValue = newVal;
307
308	updateQuantity('QUANTITY_' + basketId, basketId, ratio, bUseFloatQuantity);
309}
310
311function getCorrectRatioQuantity(quantity, ratio, bUseFloatQuantity) {
312	var newValInt = quantity * 10000,
313		ratioInt = ratio * 10000,
314		reminder = newValInt % ratioInt,
315		result = quantity,
316		bIsQuantityFloat = false,
317		i;
318	ratio = parseFloat(ratio);
319
320	if(reminder === 0) {
321		return result;
322	}
323
324	if(ratio !== 0 && ratio != 1) {
325		for(i = ratio, max = parseFloat(quantity) + parseFloat(ratio); i <= max; i = parseFloat(parseFloat(i) + parseFloat(ratio)).toFixed(2)) {
326			result = i;
327		}
328	} else if(ratio === 1) {
329		result = quantity | 0;
330	}
331
332	if(parseInt(result, 10) != parseFloat(result)) {
333		bIsQuantityFloat = true;
334	}
335
336	result = (bUseFloatQuantity === false && bIsQuantityFloat === false) ? parseInt(result, 10) : parseFloat(result).toFixed(2);
337
338	return result;
339}
340
341function recalcBasketAjax(params) {
342	BX.showWait();
343
344	var property_values = {},
345		action_var = BX('action_var').value,		
346		items = BX.findChildren(BX('cart_equipment'), {className: 'tr'}, true),
347		shelveItems = BX.findChildren(BX('shelve_equipment'), {className: 'tr'}, true),
348		postData,
349		i;	
350
351	postData = {
352		'sessid': BX.bitrix_sessid(),
353		'site_id': BX.message('SITE_ID'),
354		'props': property_values,
355		'action_var': action_var,
356		'select_props': BX('column_headers').value,
357		'offers_props': BX('offers_props').value,
358		'quantity_float': BX('quantity_float').value,
359		'count_discount_4_all_quantity': BX('count_discount_4_all_quantity').value,
360		'price_vat_show_value': BX('price_vat_show_value').value,
361		'hide_coupon': BX('hide_coupon').value,
362		'use_prepayment': BX('use_prepayment').value
363	};
364	postData[action_var] = 'recalculate';
365	if(!!params && typeof params === 'object') {
366		for(i in params) {
367			if(params.hasOwnProperty(i))
368				postData[i] = params[i];
369		}
370	}
371
372	if(!!items && items.length > 0) {
373		for(i = 0; items.length > i; i++)
374			postData['QUANTITY_' + items[i].id] = BX('QUANTITY_' + items[i].id).value;
375	}
376
377	if(!!shelveItems && shelveItems.length > 0) {
378		for(i = 0; shelveItems.length > i; i++)
379			postData['DELAY_' + shelveItems[i].id] = 'Y';
380	}
381
382	BX.ajax({
383		url: '/bitrix/components/bitrix/sale.basket.basket/ajax.php',
384		method: 'POST',
385		data: postData,
386		dataType: 'json',
387		onsuccess: function(result) {
388			BX.closeWait();
389			updateBasketTable(null, result);
390		}
391	});
392}
393
394function deleteCoupon(e) {
395	var target = BX.proxy_context,
396		value;
397
398	if(!!target && target.hasAttribute('data-coupon')) {
399		value = target.getAttribute('data-coupon');
400		if(!!value && value.length > 0) {
401			recalcBasketAjax({'delete_coupon' : value});
402		}
403	}
404}
405
406BX.ready(function() {
407	var couponBlock = BX('cart-coupon');
408	if(!!couponBlock)
409		BX.bindDelegate(couponBlock, 'click', { 'attribute': 'data-coupon' }, BX.delegate(function(e){deleteCoupon(e); }, this));
410});

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.