PageSourceSearch

https://doka-tools.ru/bitrix/components/altop/search.title/templates/.default/script.js?146012358817312

js doka-tools.ru collected 2026-10-05 00:00:34 UTC 17,312 bytes, 572 lines download raw bytes

1(function (window) {
2
3	if(!!window.JCCatalogSectionSearch) {
4		return;
5	}
6
7	window.JCCatalogSectionSearch = function (arParams) {
8		this.productType = 0;
9		this.visual = {
10			ID: '',
11			PICT_ID: '',
12			PRICE_ID: '',
13			BUY_ID: '',
14		};
15		this.product = {
16			name: '',
17			id: 0,
18		};
19
20		this.offersView = null;
21		this.offers = [];
22		this.offerNum = 0;
23		this.treeProps = [];
24		this.obTreeRows = [];
25		this.selectedValues = {};
26		this.selectProps = [];
27		this.obSelectRows = [];
28
29		this.obProduct = null;
30		this.obPict = null;
31		this.obPrice = null;
32		this.obBuy = null;
33		this.obTree = null;
34		this.obSelect = null;
35			
36		this.errorCode = 0;
37
38		if('object' === typeof arParams) {
39			this.productType = parseInt(arParams.PRODUCT_TYPE, 10);
40			this.visual = arParams.VISUAL;
41
42			switch (this.productType) {
43				case 1://product
44				case 2://set
45					if(!!arParams.PRODUCT && 'object' === typeof(arParams.PRODUCT)) {
46						this.product.name = arParams.PRODUCT.NAME;
47						this.product.id = arParams.PRODUCT.ID;
48						if(!!arParams.SELECT_PROPS) {
49							this.selectProps = arParams.SELECT_PROPS;
50						}
51					} else {
52						this.errorCode = -1;
53					}
54					break;
55				case 3://sku
56					if(!!arParams.OFFERS && BX.type.isArray(arParams.OFFERS)) {
57						if(!!arParams.PRODUCT && 'object' === typeof(arParams.PRODUCT)) {
58							this.product.name = arParams.PRODUCT.NAME;
59							this.product.id = arParams.PRODUCT.ID;
60							if(!!arParams.SELECT_PROPS) {
61								this.selectProps = arParams.SELECT_PROPS;
62							}
63						}
64						if(!!arParams.OFFERS_VIEW) {
65							this.offersView = arParams.OFFERS_VIEW;
66						}
67						this.offers = arParams.OFFERS;
68						this.offerNum = 0;
69						if(!!arParams.OFFER_SELECTED) {
70							this.offerNum = parseInt(arParams.OFFER_SELECTED, 10);
71						}
72						if(isNaN(this.offerNum)) {
73							this.offerNum = 0;
74						}
75						if(!!arParams.TREE_PROPS) {
76							this.treeProps = arParams.TREE_PROPS;
77						}
78					} else {
79						this.errorCode = -1;
80					}
81					break;
82				default:
83					this.errorCode = -1;
84			}
85		}
86		if(0 === this.errorCode) {
87			BX.ready(BX.delegate(this.Init,this));
88		}
89	};
90
91	window.JCCatalogSectionSearch.prototype.Init = function() {
92		var i = 0,
93		strPrefix = '',
94		selPrefix = '',
95		TreeItems = null,
96		SelectItems = null;
97
98		this.obProduct = BX(this.visual.ID);
99		if(!this.obProduct) {
100			this.errorCode = -1;
101		}
102		
103		if(3 === this.productType) {
104			if("LIST" !== this.offersView) {
105				this.obPict = BX(this.visual.PICT_ID);
106				if(!this.obPict) {
107					this.errorCode = -16;
108				}
109
110				this.obPrice = BX(this.visual.PRICE_ID);
111				if(!this.obPrice) {
112					this.errorCode = -16;
113				}
114
115				this.obBuy = BX(this.visual.BUY_ID);
116				if(!this.obBuy) {
117					this.errorCode = -16;
118				}
119
120				if(!!this.visual.TREE_ID) {
121					this.obTree = BX(this.visual.TREE_ID);
122					if(!this.obTree) {
123						this.errorCode = -256;
124					}
125					strPrefix = this.visual.TREE_ITEM_ID;
126					for(i = 0; i < this.treeProps.length; i++) {
127						this.obTreeRows[i] = {
128							LIST: BX(strPrefix+this.treeProps[i].ID+'_list'),
129							CONT: BX(strPrefix+this.treeProps[i].ID+'_cont')
130						};
131						if(!this.obTreeRows[i].LIST || !this.obTreeRows[i].CONT) {
132							this.errorCode = -512;
133							break;
134						}
135					}
136				}
137			}
138		}
139
140		if(!!this.visual.SELECT_PROP_ID) {
141			this.obSelect = BX(this.visual.SELECT_PROP_ID);
142			if(!this.obSelect) {
143				this.errorCode = -256;
144			}
145			selPrefix = this.visual.SELECT_PROP_ITEM_ID;
146			for(i = 0; i < this.selectProps.length; i++) {
147				this.obSelectRows[i] = BX(selPrefix+this.selectProps[i].ID);
148				if(!this.obSelectRows[i]) {
149					this.errorCode = -512;
150					break;
151				}
152			}
153		}
154
155		if(0 === this.errorCode) {
156			switch (this.productType) {
157				case 1://product
158					if(!!this.obSelect) {
159						SelectItems = BX.findChildren(this.obSelect, {tagName: 'li'}, true);
160						if(!!SelectItems && 0 < SelectItems.length) {
161							for(i = 0; i < SelectItems.length; i++) {
162								BX.bind(SelectItems[i], 'click', BX.delegate(this.SelectProp, this));
163							}
164							this.SetSelectCurrent();
165						}
166					}
167					break;
168				case 3://sku
169					if("LIST" !== this.offersView) {
170						TreeItems = BX.findChildren(this.obTree, {tagName: 'li'}, true);
171						if(!!TreeItems && 0 < TreeItems.length) {
172							for(i = 0; i < TreeItems.length; i++) {
173								BX.bind(TreeItems[i], 'click', BX.delegate(this.SelectOfferProp, this));
174							}
175						}
176						this.SetCurrent();
177					}
178
179					if(!!this.obSelect) {
180						SelectItems = BX.findChildren(this.obSelect, {tagName: 'li'}, true);
181						if(!!SelectItems && 0 < SelectItems.length) {
182							for(i = 0; i < SelectItems.length; i++) {
183								BX.bind(SelectItems[i], 'click', BX.delegate(this.SelectProp, this));
184							}
185							this.SetSelectCurrent();
186						}					
187					}
188					break;
189			}
190		}
191	};
192
193	window.JCCatalogSectionSearch.prototype.SelectProp = function() {
194		var i = 0,
195		RowItems = null,
196		ActiveItems = null,
197		selPropValueArr = [],
198		SelectName = null,
199		SelectValue = null,		
200		selAskOrderValueArr = [],
201		selPropValue = null,		
202		selAskOrderValue = null,
203		selDelayOnclick = null,
204		selDelayOnclickArr = [],
205		selDelayOnclickNew = null,
206		target = BX.proxy_context;
207
208		if(!!target && target.hasAttribute('data-select-onevalue')) {
209			RowItems = BX.findChildren(target.parentNode, {tagName: 'li'}, false);
210			if(!!RowItems && 0 < RowItems.length) {
211				for(i = 0; i < RowItems.length; i++) {
212					BX.removeClass(RowItems[i], 'active');
213				}
214			}
215			BX.addClass(target, 'active');
216		}
217
218		ActiveItems = BX.findChildren(this.obSelect, {tagName: 'li', className: 'active'}, true);
219		if(!!ActiveItems && 0 < ActiveItems.length) {
220			for(i = 0; i < ActiveItems.length; i++) {
221				selPropValueArr[i] = ActiveItems[i].getAttribute('data-select-onevalue');
222				/*ASK_ORDER*/
223				SelectName = BX.findChildren(ActiveItems[i].parentNode.parentNode.parentNode, {className: 'h3'}, true);
224				SelectValue = BX.findChildren(ActiveItems[i], {tagName: 'span'}, true);
225				if((!!SelectName && 0 < SelectName.length) && (!!SelectValue && 0 < SelectValue.length)) {					
226					selAskOrderValueArr[i] = SelectName[0].innerHTML+': '+SelectValue[0].innerHTML;
227				}
228			}
229		}
230
231		selPropValue = selPropValueArr.join('||');		
232		selAskOrderValue = selAskOrderValueArr.join('; ');
233		
234		if(!!this.offers && 0 < this.offers.length) {
235			for(i = 0; i < this.offers.length; i++) {
236				/*CART*/
237				if(!!BX('select_props_search_'+this.offers[i].ID))
238					BX('select_props_search_'+this.offers[i].ID).value = selPropValue;
239				/*DELAY*/
240				if(!!BX('catalog-item-delay-search-'+this.offers[i].ID)) {
241					selDelayOnclick = BX('catalog-item-delay-search-'+this.offers[i].ID).getAttribute('onclick');
242					selDelayOnclickArr = selDelayOnclick.split("',");
243					selDelayOnclickArr[3] = " '"+selPropValue;
244					selDelayOnclickNew = selDelayOnclickArr.join("',");
245					BX('catalog-item-delay-search-'+this.offers[i].ID).setAttribute('onclick', selDelayOnclickNew);
246				}
247				/*BOC*/
248				if(!!BX('boc_element_select_props_search_'+this.offers[i].ID))
249					BX('boc_element_select_props_search_'+this.offers[i].ID).value = selPropValue;
250				/*ASK_PRICE*/
251				if(!!BX('ask_price_message_search_'+this.offers[i].ID))
252					BX('ask_price_message_search_'+this.offers[i].ID).innerHTML = this.AskPriceMessageNew[i]+'; '+selAskOrderValue+')';
253				/*ORDER*/
254				if(!!BX('order_message_search_'+this.offers[i].ID))
255					BX('order_message_search_'+this.offers[i].ID).innerHTML = this.OrderMessageNew[i]+'; '+selAskOrderValue+')';
256			}
257		} else {
258			/*CART*/
259			if(!!BX('select_props_search_'+this.product.id))
260				BX('select_props_search_'+this.product.id).value = selPropValue;			
261		}
262	}
263
264	window.JCCatalogSectionSearch.prototype.SelectOfferProp = function() {
265		var i = 0,
266		value = '',
267		strTreeValue = '',
268		arTreeItem = [],
269		RowItems = null,
270		target = BX.proxy_context;
271
272		if(!!target && target.hasAttribute('data-treevalue')) {
273			strTreeValue = target.getAttribute('data-treevalue');
274			arTreeItem = strTreeValue.split('_');
275			if(this.SearchOfferPropIndex(arTreeItem[0], arTreeItem[1])) {
276				RowItems = BX.findChildren(target.parentNode, {tagName: 'li'}, false);
277				if(!!RowItems && 0 < RowItems.length) {
278					for(i = 0; i < RowItems.length; i++) {
279						value = RowItems[i].getAttribute('data-onevalue');
280						if(value === arTreeItem[1]) {
281							BX.addClass(RowItems[i], 'active');
282						} else {
283							BX.removeClass(RowItems[i], 'active');
284						}
285					}
286				}
287			}
288		}
289	};
290
291	window.JCCatalogSectionSearch.prototype.SearchOfferPropIndex = function(strPropID, strPropValue) {
292		var strName = '',
293		arShowValues = false,
294		i, j,
295		arCanBuyValues = [],
296		index = -1,
297		arFilter = {};
298		
299		for(i = 0; i < this.treeProps.length; i++) {
300			if(this.treeProps[i].ID === strPropID) {
301				index = i;
302				break;
303			}
304		}
305
306		if(-1 < index) {
307			for(i = 0; i < index; i++) {
308				strName = 'PROP_'+this.treeProps[i].ID;
309				arFilter[strName] = this.selectedValues[strName];
310			}
311			strName = 'PROP_'+this.treeProps[index].ID;
312			arShowValues = this.GetRowValues(arFilter, strName);
313			if(!arShowValues) {
314				return false;
315			}
316			if(!BX.util.in_array(strPropValue, arShowValues)) {
317				return false;
318			}
319			arFilter[strName] = strPropValue;
320			for(i = index+1; i < this.treeProps.length; i++) {
321				strName = 'PROP_'+this.treeProps[i].ID;
322				arShowValues = this.GetRowValues(arFilter, strName);
323				if(!arShowValues) {
324					return false;
325				}
326				arCanBuyValues = arShowValues;
327				if(!!this.selectedValues[strName] && BX.util.in_array(this.selectedValues[strName], arCanBuyValues)) {
328					arFilter[strName] = this.selectedValues[strName];
329				} else {
330					arFilter[strName] = arCanBuyValues[0];
331				}
332				this.UpdateRow(i, arFilter[strName], arShowValues, arCanBuyValues);
333			}
334			this.selectedValues = arFilter;
335			this.ChangeInfo();
336		}
337		return true;
338	};
339
340	window.JCCatalogSectionSearch.prototype.UpdateRow = function(intNumber, activeID, showID, canBuyID) {
341		var i = 0,
342		showI = 0,
343		value = '',
344		obData = {},
345		isCurrent = false,
346		selectIndex = 0,
347		RowItems = null;
348
349		if(-1 < intNumber && intNumber < this.obTreeRows.length) {
350			RowItems = BX.findChildren(this.obTreeRows[intNumber].LIST, {tagName: 'li'}, false);
351			if(!!RowItems && 0 < RowItems.length) {
352				obData = {
353					props: { className: '' },
354					style: {}
355				};
356				for(i = 0; i < RowItems.length; i++) {
357					value = RowItems[i].getAttribute('data-onevalue');
358					isCurrent = (value === activeID);
359					if(BX.util.in_array(value, canBuyID)) {
360						obData.props.className = (isCurrent ? 'active' : '');
361					} else {
362						obData.props.className = (isCurrent ? 'active hidden' : 'hidden');
363					}
364					obData.style.display = 'none';
365					if(BX.util.in_array(value, showID)) {
366						obData.style.display = '';
367						if(isCurrent) {
368							selectIndex = showI;
369						}
370						showI++;
371					}
372					BX.adjust(RowItems[i], obData);
373				}
374
375				obData = {
376					style: {}
377				};
378				
379				BX.adjust(this.obTreeRows[intNumber].LIST, obData);
380			}
381		}
382	};
383
384	window.JCCatalogSectionSearch.prototype.GetRowValues = function(arFilter, index) {
385		var i = 0,
386		j,
387		arValues = [],
388		boolSearch = false,
389		boolOneSearch = true;
390
391		if(0 === arFilter.length) {
392			for(i = 0; i < this.offers.length; i++) {
393				if(!BX.util.in_array(this.offers[i].TREE[index], arValues)) {
394					arValues[arValues.length] = this.offers[i].TREE[index];
395				}
396			}
397			boolSearch = true;
398		} else {
399			for(i = 0; i < this.offers.length; i++) {
400				boolOneSearch = true;
401				for(j in arFilter) {
402					if(arFilter[j] !== this.offers[i].TREE[j]) {
403						boolOneSearch = false;
404						break;
405					}
406				}
407				if(boolOneSearch) {
408					if(!BX.util.in_array(this.offers[i].TREE[index], arValues)) {
409						arValues[arValues.length] = this.offers[i].TREE[index];
410					}
411					boolSearch = true;
412				}
413			}
414		}
415		return (boolSearch ? arValues : false);
416	};
417
418	window.JCCatalogSectionSearch.prototype.SetSelectCurrent = function() {
419		var i = 0,
420		SelectItems = null,
421		selPropValueArr = [],
422		SelectName = null,
423		SelectValue = null,		
424		selAskOrderValueArr = [],
425		selPropValue = null,		
426		selAskOrderValue = null,		
427		selDelayOnclick = null,
428		selDelayOnclickArr = [],
429		selDelayOnclickNew = null;
430		this.AskPriceMessageNew = [];
431		this.OrderMessageNew = [];
432		
433		for(i = 0; i < this.obSelectRows.length; i++) {
434			SelectItems = BX.findChildren(this.obSelectRows[i], {tagName: 'li'}, true);
435			if(!!SelectItems && 0 < SelectItems.length) {
436				BX.addClass(SelectItems[0], 'active');
437				selPropValueArr[i] = SelectItems[0].getAttribute('data-select-onevalue');
438			}
439			/*ASK_ORDER*/
440			SelectName = BX.findChildren(this.obSelectRows[i], {className: 'h3'}, true);
441			SelectValue = BX.findChildren(SelectItems[0], {tagName: 'span'}, true);
442			if((!!SelectName && 0 < SelectName.length) && (!!SelectValue && 0 < SelectValue.length)) {				
443				selAskOrderValueArr[i] = SelectName[0].innerHTML+': '+SelectValue[0].innerHTML;
444			}
445		}
446
447		selPropValue = selPropValueArr.join('||');		
448		selAskOrderValue = selAskOrderValueArr.join('; ');
449		
450		if(!!this.offers && 0 < this.offers.length) {
451			for(i = 0; i < this.offers.length; i++) {
452				/*CART*/
453				if(!!BX('select_props_search_'+this.offers[i].ID))
454					BX('select_props_search_'+this.offers[i].ID).value = selPropValue;
455				/*DELAY*/
456				if(!!BX('catalog-item-delay-search-'+this.offers[i].ID)) {
457					selDelayOnclick = BX('catalog-item-delay-search-'+this.offers[i].ID).getAttribute('onclick');
458					selDelayOnclickArr = selDelayOnclick.split("',");
459					selDelayOnclickArr[3] = " '"+selPropValue;
460					selDelayOnclickNew = selDelayOnclickArr.join("',");
461					BX('catalog-item-delay-search-'+this.offers[i].ID).setAttribute('onclick', selDelayOnclickNew);
462				}
463				/*BOC*/
464				if(!!BX('boc_element_select_props_search_'+this.offers[i].ID))
465					BX('boc_element_select_props_search_'+this.offers[i].ID).value = selPropValue;
466				/*ASK_PRICE*/
467				if(!!BX('ask_price_message_search_'+this.offers[i].ID)) {
468					this.AskPriceMessage = BX('ask_price_message_search_'+this.offers[i].ID).innerHTML;
469					this.AskPriceMessageArr = this.AskPriceMessage.split(')');
470					this.AskPriceMessageNew[i] = this.AskPriceMessageArr[0];
471					BX('ask_price_message_search_'+this.offers[i].ID).innerHTML = this.AskPriceMessageNew[i]+'; '+selAskOrderValue+')';
472				}
473				/*ORDER*/
474				if(!!BX('order_message_search_'+this.offers[i].ID)) {
475					this.OrderMessage = BX('order_message_search_'+this.offers[i].ID).innerHTML;
476					this.OrderMessageArr = this.OrderMessage.split(')');
477					this.OrderMessageNew[i] = this.OrderMessageArr[0];
478					BX('order_message_search_'+this.offers[i].ID).innerHTML = this.OrderMessageNew[i]+'; '+selAskOrderValue+')';
479				}
480			}
481		} else {
482			/*CART*/
483			if(!!BX('select_props_search_'+this.product.id))
484				BX('select_props_search_'+this.product.id).value = selPropValue;			
485		}
486	}
487
488	window.JCCatalogSectionSearch.prototype.SetCurrent = function() {
489		var i = 0,
490		j = 0,
491		arCanBuyValues = [],
492		strName = '',
493		arShowValues = false,
494		arFilter = {},
495		current = this.offers[this.offerNum].TREE;
496
497		for(i = 0; i < this.treeProps.length; i++) {
498			strName = 'PROP_'+this.treeProps[i].ID;
499			arShowValues = this.GetRowValues(arFilter, strName);
500			if(!arShowValues) {
501				break;
502			}
503			if(BX.util.in_array(current[strName], arShowValues)) {
504				arFilter[strName] = current[strName];
505			} else {
506				arFilter[strName] = arShowValues[0];
507				this.offerNum = 0;
508			}
509			arCanBuyValues = arShowValues;
510			this.UpdateRow(i, arFilter[strName], arShowValues, arCanBuyValues);
511		}
512		this.selectedValues = arFilter;
513		this.ChangeInfo();
514	};
515
516	window.JCCatalogSectionSearch.prototype.ChangeInfo = function() {
517		var i = 0,
518		j,
519		index = -1,
520		boolOneSearch = true;
521
522		for(i = 0; i < this.offers.length; i++) {
523			boolOneSearch = true;
524			for(j in this.selectedValues) {
525				if(this.selectedValues[j] !== this.offers[i].TREE[j]) {
526					boolOneSearch = false;
527					break;
528				}
529			}
530			if(boolOneSearch) {
531				index = i;
532				break;
533			}
534		}
535		if(-1 < index) {
536			this.setPict(this.product.id, this.offers[index].ID);
537			this.setPrice(this.product.id, this.offers[index].ID);
538			this.setBuy(this.product.id, this.offers[index].ID);
539			this.offerNum = index;
540		}
541	};
542
543	window.JCCatalogSectionSearch.prototype.setPict = function(item_id, offer_id) {
544		PictItems = BX.findChildren(this.obPict, {className: 'img'}, true);
545		if(!!PictItems && 0 < PictItems.length) {
546			for(i = 0; i < PictItems.length; i++) {
547				BX.addClass(PictItems[i], 'hidden');
548			}
549		}
550		BX.removeClass(BX('img_search_'+item_id+'_'+offer_id), 'hidden');
551	};
552
553	window.JCCatalogSectionSearch.prototype.setPrice = function(item_id, offer_id) {
554		PriceItems = BX.findChildren(this.obPrice, {className: 'price'}, true);
555		if(!!PriceItems && 0 < PriceItems.length) {
556			for(i = 0; i < PriceItems.length; i++) {
557				BX.addClass(PriceItems[i], 'hidden');
558			}
559		}
560		BX.removeClass(BX('price_search_'+item_id+'_'+offer_id), 'hidden');
561	};
562
563	window.JCCatalogSectionSearch.prototype.setBuy = function(item_id, offer_id) {
564		BuyItems = BX.findChildren(this.obBuy, {className: 'buy_more'}, true);
565		if(!!BuyItems && 0 < BuyItems.length) {
566			for(i = 0; i < BuyItems.length; i++) {
567				BX.addClass(BuyItems[i], 'hidden');
568			}
569		}
570		BX.removeClass(BX('buy_more_search_'+item_id+'_'+offer_id), 'hidden');
571	};
572})(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.