PageSourceSearch

https://moscosmetics.ru/local/templates/aspro_max_cosmetic/compone…/corp/script.js?174358577610699

js moscosmetics.ru collected 2026-09-28 23:17:24 UTC 10,699 bytes, 432 lines download raw bytes

1function JCTitleSearch4(arParams)
2{
3	var _this = this;
4	
5	this.arParams = {
6		'AJAX_PAGE': arParams.AJAX_PAGE,
7		'CONTAINER_ID': arParams.CONTAINER_ID,
8		'INPUT_ID': arParams.INPUT_ID,
9		'INPUT_ID_TMP': arParams.INPUT_ID_TMP,
10		'MIN_QUERY_LEN': parseInt(arParams.MIN_QUERY_LEN)
11	};
12
13	if(arParams.WAIT_IMAGE)
14		this.arParams.WAIT_IMAGE = arParams.WAIT_IMAGE;
15	if(arParams.MIN_QUERY_LEN <= 0)
16		arParams.MIN_QUERY_LEN = 1;
17
18	this.cache = [];
19	this.cache_key = null;
20
21	this.startText = '';
22	this.running = false;
23	this.needRunAgain = false;
24	this.currentRow = -1;
25	this.RESULT = null;
26	this.CONTAINER = null;
27	this.INPUT = null;
28	this.TYPE = null;
29	this.WAIT = null;
30
31	this.ShowResult = function(result)
32	{
33		if(BX.type.isString(result))
34		{
35			_this.RESULT.innerHTML = result;
36		}
37
38		_this.RESULT.style.display = _this.RESULT.innerHTML !== '' ? 'block' : 'none';
39		var pos = _this.adjustResultNode();
40
41		//adjust left column to be an outline
42		var res_pos;
43		var th;
44		var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true);
45		if(tbl)
46		{
47			th = BX.findChild(tbl, {'tag':'th'}, true);
48		}
49		
50		if(th)
51		{
52			var tbl_pos = BX.pos(tbl);
53			tbl_pos.width = tbl_pos.right - tbl_pos.left;
54
55			var th_pos = BX.pos(th);
56			th_pos.width = th_pos.right - th_pos.left;
57			th.style.width = th_pos.width + 'px';
58
59			_this.RESULT.style.width = (pos.width + th_pos.width) + 'px';
60
61			//Move table to left by width of the first column
62			_this.RESULT.style.left = '0px';//(pos.left - th_pos.width - 1)+ 'px';
63
64			//Shrink table when it's too wide
65			if((tbl_pos.width - th_pos.width) > pos.width)
66				_this.RESULT.style.width = (pos.width + th_pos.width -1) + 'px';
67
68			//Check if table is too wide and shrink result div to it's width
69			tbl_pos = BX.pos(tbl);
70			res_pos = BX.pos(_this.RESULT);
71			if(res_pos.right > tbl_pos.right)
72			{
73				_this.RESULT.style.width = (tbl_pos.right - tbl_pos.left) + 'px';
74			}
75		}
76
77		var fade;
78		if(tbl) fade = BX.findChild(_this.RESULT, {'class':'title-search-fader'}, true);
79		if(fade && th)
80		{
81			res_pos = BX.pos(_this.RESULT);
82			fade.style.left = (res_pos.right - res_pos.left - 18) + 'px';
83			fade.style.width = 18 + 'px';
84			fade.style.top = 0 + 'px';
85			fade.style.height = (res_pos.bottom - res_pos.top) + 'px';
86			fade.style.display = 'block';
87		}
88
89	};
90
91	this.onKeyPress = function(keyCode)
92	{
93		var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true);
94		if(!tbl)
95			return false;
96
97		var i;
98		var cnt = tbl.rows.length;
99
100		switch (keyCode)
101		{
102		case 27: // escape key - close search div
103			_this.RESULT.style.display = 'none';
104			_this.currentRow = -1;
105			_this.UnSelectAll();
106		return true;
107
108		case 40: // down key - navigate down on search results
109			if(_this.RESULT.style.display == 'none')
110				_this.RESULT.style.display = 'block';
111
112			var first = -1;
113			for(i = 0; i < cnt; i++)
114			{
115				if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
116				{
117					if(first == -1)
118						first = i;
119
120					if(_this.currentRow < i)
121					{
122						_this.currentRow = i;
123						break;
124					}
125					else if(tbl.rows[i].className == 'title-search-selected')
126					{
127						tbl.rows[i].className = '';
128					}
129				}
130			}
131
132			if(i == cnt && _this.currentRow != i)
133				_this.currentRow = first;
134
135			tbl.rows[_this.currentRow].className = 'title-search-selected';
136		return true;
137
138		case 38: // up key - navigate up on search results
139			if(_this.RESULT.style.display == 'none')
140				_this.RESULT.style.display = 'block';
141
142			var last = -1;
143			for(i = cnt-1; i >= 0; i--)
144			{
145				if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
146				{
147					if(last == -1)
148						last = i;
149
150					if(_this.currentRow > i)
151					{
152						_this.currentRow = i;
153						break;
154					}
155					else if(tbl.rows[i].className == 'title-search-selected')
156					{
157						tbl.rows[i].className = '';
158					}
159				}
160			}
161
162			if(i < 0 && _this.currentRow != i)
163				_this.currentRow = last;
164
165			tbl.rows[_this.currentRow].className = 'title-search-selected';
166		return true;
167
168		case 13: // enter key - choose current search result
169			if(_this.RESULT.style.display == 'block')
170			{
171				for(i = 0; i < cnt; i++)
172				{
173					if(_this.currentRow == i)
174					{
175						if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
176						{
177							var a = BX.findChild(tbl.rows[i], {'tag':'a'}, true);
178							if(a)
179							{
180								window.location = a.href;
181								return true;
182							}
183						}
184					}
185				}
186			}
187		return false;
188		}
189
190		return false;
191	};
192
193	this.onTimeout = function()
194	{
195		_this.onChange(function(){
196			setTimeout(_this.onTimeout, 500);
197		});
198	};
199
200	this.onChange = function(callback)
201	{
202		if (_this.running){
203			_this.needRunAgain = true;
204			return;
205		}
206		_this.running = true;
207
208		let type = 'catalog';
209		if (this.TYPE) {
210			type = this.TYPE.value;
211		}
212
213		if(
214			(
215				_this.INPUT.value != _this.oldValue
216				&& _this.INPUT.value != _this.startText
217			)
218			|| type != _this.oldType
219		){
220			_this.oldValue = _this.INPUT.value;
221			_this.oldType = type;
222
223			if(_this.INPUT.value.length >= _this.arParams.MIN_QUERY_LEN)
224			{
225				_this.cache_key = _this.arParams.INPUT_ID + '|' + _this.INPUT.value + '|' + type;
226				if(_this.cache[_this.cache_key] == null)
227				{
228					if(_this.WAIT)
229					{
230						var pos = BX.pos(_this.INPUT);
231						var height = (pos.bottom - pos.top)-2;
232						_this.WAIT.style.top = (pos.top+1) + 'px';
233						_this.WAIT.style.height = height + 'px';
234						_this.WAIT.style.width = height + 'px';
235						_this.WAIT.style.left = (pos.right - height + 2) + 'px';
236						_this.WAIT.style.display = 'block';
237					}
238
239					BX.ajax.post(
240						_this.arParams.AJAX_PAGE,
241						{
242							'ajax_call':'y',
243							'INPUT_ID':_this.arParams.INPUT_ID_TMP,
244							'q':_this.INPUT.value,
245							'l':_this.arParams.MIN_QUERY_LEN,
246							'type': type,
247						},
248						function(result)
249						{
250							_this.cache[_this.cache_key] = result;
251							_this.ShowResult(result);
252							_this.currentRow = -1;
253							_this.EnableMouseEvents();
254							if(_this.WAIT)
255								_this.WAIT.style.display = 'none';
256							if (!!callback)
257								callback();
258							_this.running = false;
259
260							if(_this.needRunAgain){
261								_this.needRunAgain = false;
262								_this.onChange(callback);
263							}
264						}
265					);
266					return;
267				}
268				else
269				{
270					_this.ShowResult(_this.cache[_this.cache_key]);
271					_this.currentRow = -1;
272					_this.EnableMouseEvents();
273				}
274			}
275			else
276			{
277				_this.RESULT.style.display = 'none';
278				_this.currentRow = -1;
279				_this.UnSelectAll();
280			}
281		}
282		if (!!callback)
283			callback();
284		_this.running = false;
285	};
286
287	this.UnSelectAll = function()
288	{
289		var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true);
290		if(tbl)
291		{
292			var cnt = tbl.rows.length;
293			for(var i = 0; i < cnt; i++)
294				tbl.rows[i].className = '';
295		}
296	};
297
298	this.EnableMouseEvents = function()
299	{
300		var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true);
301		if(tbl)
302		{
303			var cnt = tbl.rows.length;
304			for(var i = 0; i < cnt; i++)
305				if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
306				{
307					tbl.rows[i].id = 'row_' + i;
308					tbl.rows[i].onmouseover = function (e) {
309						if(_this.currentRow != this.id.substr(4))
310						{
311							_this.UnSelectAll();
312							this.className = 'title-search-selected';
313							_this.currentRow = this.id.substr(4);
314						}
315					};
316					tbl.rows[i].onmouseout = function (e) {
317						this.className = '';
318						_this.currentRow = -1;
319					};
320				}
321		}
322	};
323
324	this.onFocusLost = function(hide)
325	{
326		setTimeout(function(){_this.RESULT.style.display = 'none';}, 300);
327		// _this.RESULT.style.display = 'none';
328	};
329
330	this.onFocusGain = function()
331	{
332		if(_this.RESULT.innerHTML.length)
333			_this.ShowResult();
334	};
335
336	this.onKeyDown = function(e)
337	{
338		if(!e)
339			e = window.event;
340		if (_this.RESULT.style.display == 'block')
341		{
342			if(_this.onKeyPress(e.keyCode))
343				return BX.PreventDefault(e);
344		}
345	};
346
347	this.adjustResultNode = function()
348	{
349		var pos, pos_input;
350		var fixedParent = BX.findParent(_this.CONTAINER, BX.is_fixed);
351		// if(!!fixedParent)
352		// {
353		// 	_this.RESULT.style.position = 'fixed';
354		// 	_this.RESULT.style.zIndex = BX.style(fixedParent, 'z-index') + 2;
355		// 	pos = BX.pos(_this.CONTAINER, true);
356		// }
357		// else
358		// {
359			_this.RESULT.style.position = 'absolute';
360			pos = BX.pos(_this.CONTAINER);
361		// }
362		pos_input = BX.pos(_this.INPUT);
363
364		pos.width = pos.right - pos.left;
365		_this.RESULT.style.top = '100%';
366		_this.RESULT.style.left = '0px';//pos_input.left + 'px';
367
368		if($(_this.INPUT).closest('.inline-search-block.with-close').length)
369			_this.RESULT.style.width = pos_input.width + 'px';
370		else
371			_this.RESULT.style.width = pos.width + 'px';
372		return pos;
373	};
374
375	this._onContainerLayoutChange = function()
376	{
377		if(_this.RESULT.style.display !== "none" && _this.RESULT.innerHTML !== '')
378		{
379			_this.adjustResultNode();
380		}
381	};
382	this.Init = function()
383	{
384		this.CONTAINER = document.getElementById(this.arParams.CONTAINER_ID);
385		BX.addCustomEvent(this.CONTAINER, "OnNodeLayoutChange", this._onContainerLayoutChange);
386
387		this.RESULT = this.CONTAINER.appendChild(document.createElement("DIV"));
388
389		this.RESULT.className = 'title-search-result '+this.arParams.INPUT_ID;
390		this.INPUT = document.getElementById(this.arParams.INPUT_ID);
391		this.startText = this.oldValue = this.INPUT.value;
392		BX.bind(this.INPUT, 'focus', function(e) {
393			_this.onFocusGain()
394		});
395		BX.bind(this.INPUT, 'blur', function(e) {
396			if(!$(e.relatedTarget).hasClass('bx_item_block')){
397				if (window.matchMedia("(min-width: 993px)").matches) {
398					setTimeout(function(){
399						if(!$(_this.INPUT).closest('form').find('.dropdown-select.searchtype .dropdown-select__title.opened').length){
400							_this.onFocusLost();
401						}
402					}, 100);
403				}
404			}
405		});
406
407		this.TYPE = this.CONTAINER ? this.CONTAINER.querySelector('.dropdown-select.searchtype input[name="type"]') : null;
408
409		if(BX.browser.IsSafari() || BX.browser.IsIE())
410			this.INPUT.onkeydown = this.onKeyDown;
411		else
412			this.INPUT.onkeypress = this.onKeyDown;
413
414		if(this.arParams.WAIT_IMAGE)
415		{
416			this.WAIT = document.body.appendChild(document.createElement("DIV"));
417			this.WAIT.style.backgroundImage = "url('" + this.arParams.WAIT_IMAGE + "')";
418			if(!BX.browser.IsIE())
419				this.WAIT.style.backgroundRepeat = 'none';
420			this.WAIT.style.display = 'none';
421			this.WAIT.style.position = 'absolute';
422			this.WAIT.style.zIndex = '1100';
423		}
424
425		BX.bind(this.INPUT, 'bxchange', function(e) {_this.onChange()});
426
427		if (this.TYPE) {
428			BX.bind(this.TYPE, 'change', function() {_this.onChange()});
429		}
430	};
431	BX.ready(function (){_this.Init(arParams)});
432}

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.