PageSourceSearch

https://www.allfordj.ru/local/templates/aspro_max_local/js/asproFilterHelper.js

js allfordj.ru collected 2026-09-26 02:37:28 UTC 10,787 bytes, 345 lines download raw bytes

1function asproFilterHelper(smartFilter, noAjax) {
2	this.resultDiv = $('#filter-helper');
3	this.smart = smartFilter;
4	this.noAjax = noAjax;
5	if(this.resultDiv.length) {
6		this.resultDiv.empty();
7		this.smartFilter = $('.bx_filter.bx_filter_vertical');
8		this.filterHelper = [];
9		this.getInputsInfo(this.smartFilter);
10
11		var _this = this;
12		$(document).on('click', '#filter-helper .filterHelperItem .delete_filter, #filter-helper .filterHelperItem:not(.multiple) .title-wrapper', function(e) {
13			var _el = $(e.target);
14			var id = _el.closest('.filterHelperItem').data('id');
15			var options = {};
16			options.ID = id;
17			if(_el.closest('.filterHelperItem').hasClass('multiple')) {
18				options.MULTIPLE = true;
19			}
20			if(_el.closest('.filterHelperItem').hasClass('price')) {
21				options.PRICE = true;
22			}
23			_this.clearValue(options);
24		});
25
26		$(document).on('click', '#filter-helper .filterHelperItem .select-wrapper .select-value', function(e) {
27			var _el = $(e.target);
28			var id = _el.closest('.select-value').data('id');
29			_this.clearValue({ID: id});
30		});
31	}
32}
33
34asproFilterHelper.prototype.check = function() {
35	return (this.resultDiv.length && this.smartFilter.length);
36}
37
38asproFilterHelper.prototype.getInputsInfo = function(smartFilter) {
39	if(smartFilter.length && this.check()) {
40		var _this = this;
41		this.inputs = smartFilter.find('input');
42		if(this.inputs.length) {
43			this.inputs.each(function(i, el) {
44				var _el = $(el);
45				var bPrice = _el.hasClass('min-price') || _el.hasClass('max-price');
46				var bChecked = _el.attr('checked') && !_el.attr('disabled');
47				if( bChecked || (bPrice && _el.val()) ) {
48					var title = '';
49					var code = '';
50
51					var boxWrapper = _el.closest('.bx_filter_parameters_box');
52					if(boxWrapper.length) {
53						code = boxWrapper.data('prop_code') ? boxWrapper.data('prop_code') : '';
54						var titleWrapper = boxWrapper.data('property_name');
55						if(titleWrapper !== undefined) {
56							title = titleWrapper;
57						}
58					}
59
60					var value = _el.data('title') === undefined ? '' :  _el.data('title');
61					if(!value) {
62						var label = smartFilter.find('label[for='+_el.attr('name')+']');
63						var labelFromId = smartFilter.find('label[for='+_el.attr('id')+']');
64						if(label.length) {
65							value = label.find('[title]');
66							value = value.length ? value.attr('title') : '';
67						}else if(labelFromId.length){
68							value = labelFromId.find('[title]');
69							value = labelFromId.length ? value.attr('title') : '';
70						}
71					}
72
73					if(bPrice) {
74						if(_el.hasClass('min-price')){
75							value = BX.message('FROM');
76						} else if(_el.hasClass('max-price')) {
77							value = BX.message('BEFORE');
78						}
79						value += ' '+_el.val();
80						code = _el.attr('name').replace(/_MIN|_MAX/, '');
81					}
82
83					var helperData = {
84						NAME: _el.attr('id'),
85						VALUE: value,
86						INPUT: _el,
87						TITLE: title.trim(),
88						CODE: code,
89						TYPE: bPrice ? 'price' : _el.attr('type'),
90					};
91					_this.add(helperData);
92				}
93
94			});
95		}
96	}
97}
98
99asproFilterHelper.prototype.reload = function() {
100	if(!this.check())
101		return false;
102
103	this.filterHelper = [];
104	if(this.resultDiv.length) {
105		this.resultDiv.empty();
106		this.resultDiv.hide();
107	}
108}
109
110asproFilterHelper.prototype.add = function(arItem) {
111	if(!this.check())
112		return false;
113
114	if(this.filterHelper === undefined) {
115		this.reload();
116	}
117
118	if(this.filterHelper[arItem.CODE] === undefined) {
119		this.filterHelper[arItem.CODE] = [];
120	}
121	this.filterHelper[arItem.CODE].push(arItem);
122}
123
124asproFilterHelper.prototype.show = function() {
125	if(!this.check())
126		return false;
127
128	if(this.resultDiv.length && this.filterHelper && Object.keys(this.filterHelper).length) {
129		this.resultDiv.empty();
130
131		var filterSvg = '';
132		filterSvg += '<div class="bx_filter_parameters_box_title filter_title  active-filter">';
133			filterSvg += '<i class="svg  svg-inline-icon" aria-hidden="true">';
134				filterSvg += '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="10" viewBox="0 0 12 10">';
135					filterSvg += '<path class="cls-1" d="M574.593,665.783L570,670.4V674l-2-1v-2.6l-4.6-4.614a0.94,0.94,0,0,1-.2-1.354,0.939,0.939,0,0,1,.105-0.16,0.969,0.969,0,0,1,.82-0.269h9.747a0.968,0.968,0,0,1,.82.269,0.94,0.94,0,0,1,.087.132A0.945,0.945,0,0,1,574.593,665.783Zm-8.164.216L569,668.581,571.571,666h-5.142Z" transform="translate(-563 -664)"></path>';
136				filterSvg += '</svg>';
137			filterSvg += '</i>';
138		filterSvg += '</div>';
139		this.resultDiv.append(filterSvg);
140
141		var filtersWrapper = $('<div class="filterHelperItemsWrapper"></div>');
142		this.resultDiv.append(filtersWrapper);
143
144		var _this = this;
145		for(var key in _this.filterHelper) {
146			var html = _this.getResultHTML(_this.filterHelper[key]);
147			if(html) {
148				filtersWrapper.append(html);
149			}
150		};
151
152		this.resultDiv.css('display', 'flex');
153	}
154}
155
156asproFilterHelper.prototype.clearValue = function(options) {
157	if(!this.check())
158		return false;
159
160	if( (options.MULTIPLE !== undefined && options.MULTIPLE) || (options.PRICE !== undefined && options.PRICE) ) {
161		if(options.PRICE !== undefined && options.PRICE) {
162			var min = this.smartFilter.find('input.min-price#'+options.ID+'_MIN');
163			var max = this.smartFilter.find('input.max-price#'+options.ID+'_MAX');
164			var container = min.closest('.bx_filter_parameters_box_container');
165			if(container.length) {
166				var encode = container.find("[id^=colorUnavailableActive_]").attr('id').replace('colorUnavailableActive_', '');
167				var track = window['trackBar'+encode];
168				track.leftPercent=track.rightPercent=0;
169				container.find("[id^=left_slider_]").css({'left':"0%"});
170				container.find("[id^=colorUnavailableActive_]").css({'left':"0%", 'right' : "0%"});
171				container.find("[id^=colorAvailableInactive_]").css({'left':"0%", 'right' : "0%"});
172				container.find("[id^=colorAvailableActive_]").css({'left':"0%", 'right' : "0%"});
173				container.find("[id^=right_slider_]").css({'right':"0%"});
174			}
175			if(min.length) {
176				min.val('');
177				smartFilter.keyup(min[0]);
178				$("#"+options.ID+'_MIN').val('');
179			}
180
181			if(max.length) {
182				var defaultVal = max.attr('placeholder');
183				max.val('');
184				smartFilter.keyup(max[0]);
185				$("#"+options.ID+'_MAX').val('');
186			}
187		} else {
188			var wrapper = this.smartFilter.find('[data-prop_code='+options.ID+']');
189			if(wrapper.length) {
190				var elements = wrapper.find('input');
191				if(elements.length) {
192					elements.each(function(i, el) {
193						var _el = $(el);
194						var label = _el.siblings('label[for='+_el.attr('id')+']');
195						if(label.length && label.hasClass('active')) {
196							label.trigger('click');
197						} else if(el.checked) {
198							_el.trigger('click');
199						}
200					});
201				}
202			}
203		}		
204	} else {
205		var el = $('#'+options.ID);
206		if(el.length){
207			var type = el.attr('type');
208			if(type == 'checkbox') {
209				var label = $('label[for='+options.ID+']');
210				if(label.length && label.hasClass('active')) {
211					label.trigger('click');
212				} else if(el[0].checked) {
213					el.trigger('click');
214				}
215			} else if(type == 'radio') {
216				var wrapperBox = el.closest('.bx_filter_parameters_box_container');
217				if(wrapperBox.length) {
218					var popup = wrapperBox.siblings('.popup-window').length ? wrapperBox.siblings('.popup-window') : (wrapperBox.find('.bx_filter_select_popup').length ? wrapperBox.find('.bx_filter_select_popup') : false);
219					var bSelect = popup ? true : false;
220
221					var allSelect = wrapperBox.find('[id^=all_]');
222					if(allSelect.length) {
223						var id = allSelect.attr('id');
224
225						if(bSelect) {
226							var all = popup.find('label[for='+id+']');
227
228							if(all.length) {
229								all.trigger('click');
230								popup.hide();
231								var innerPopup = popup.find('.bx_filter_select_popup');
232								if(innerPopup.length) {
233									innerPopup.show();
234								}
235							}
236						} else {
237							allSelect.trigger('click');
238						}
239					}
240					
241				}
242			}
243		};
244	}
245	if(this.noAjax){
246		this.reloadPage = true;
247	}
248
249}
250
251asproFilterHelper.prototype.apply = function() {
252	if(!this.check())
253		return false;
254
255	if(this.noAjax && this.reloadPage) {
256		var apply = this.smartFilter.find('#set_filter');
257		if(apply.length) {
258			apply.trigger('click');
259		}
260	}
261}
262
263asproFilterHelper.prototype.getResultHTML = function(el) {
264	if(!this.check())
265		return false;
266
267	if(el.length == 1) {
268		var options = el[0];
269		options.ITEM_CLASS = ' colored_theme_bg_hovered_hover ';
270		if(el[0]['TYPE'] == 'price') {
271			options.ITEM_CLASS += ' price';
272			options.NAME = options.NAME.replace(/_MIN|_MAX/, '');
273		}
274	} else if(el.length > 1) {
275		var options = {
276			NAME: el[0].CODE,
277			TITLE: el[0].TITLE,
278			VALUE: el.length+BX.message('FILTER_HELPER_VALUES'),
279			ITEM_CLASS: (el[0].TYPE == 'price' ? 'price colored_theme_bg_hovered_hover' : 'multiple'),
280			TYPE: el[0].TYPE,
281			VALUES: el,
282		};
283	} else {
284		return false;
285	}
286
287	if(options.CODE == 'in_stock') {
288		options.TITLE = '';
289	}
290
291	var closeSvg = '';
292	closeSvg += '<svg xmlns="http://www.w3.org/2000/svg" width="8.031" height="8" viewBox="0 0 8.031 8">';
293		closeSvg += '<path class="cls-1" d="M756.41,668.967l2.313,2.315a1,1,0,0,1-1.415,1.409L755,670.379l-2.309,2.312a1,1,0,0,1-1.414-1.409l2.312-2.315-2.281-2.284a1,1,0,1,1,1.414-1.409L755,667.555l2.277-2.281a1,1,0,1,1,1.414,1.409Z" transform="translate(-751 -665)"></path>';
294	closeSvg += '</svg>';
295
296	var resultText = '';
297	resultText += '<div class="filterHelperItem colored_theme_bg rounded3'+(options.ITEM_CLASS === undefined ? '' : ' '+options.ITEM_CLASS)+'" data-id="'+options['NAME']+'">';
298
299		resultText += '<div class="title-wrapper colored_theme_bg_hovered_hover">';
300			if(options['TITLE']) {
301				resultText += '<span class="title">';
302					resultText += options['TITLE']+': ';
303				resultText += '</span>';
304			}
305
306			resultText += '<span class="value">';
307				if(options.TYPE == 'price' && options.VALUES !== undefined) {
308					options.VALUES.forEach(function(el, i) {
309						resultText += el.VALUE+' ';
310					});
311				} else {
312					resultText += options['VALUE'];
313				}
314			resultText += '</span>';
315		resultText += '</div>';
316
317		resultText += '<span class="delete_filter colored_theme_bg_hovered_hover">';
318			resultText += closeSvg;
319		resultText += '</span>';
320
321		if(options.VALUES !== undefined && options.TYPE != 'price') {
322			resultText += '<div class="select-wrapper">';
323				resultText += '<div class="select-inner rounded3">';
324					options.VALUES.forEach(function(el, i) {
325						resultText += '<div class="select-value" data-id="'+el['NAME']+'">';
326							resultText += el.VALUE;
327							resultText += closeSvg;
328						resultText += '</div>';
329					});
330				resultText += '</div>';
331			resultText += '</div>';
332		}
333
334	resultText += '</div>';
335
336
337	return resultText;
338}
339
340
341
342// $(document).on('click', '#filter-helper .filterHelperItem.multiple .title-wrapper', function(e) {
343// 	var _el = $(this);
344// 	_el.siblings('.select-wrapper').fadeToggle();
345// });

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.