PageSourceSearch

https://www.unionmart.ru/bitrix/templates/design2025/components/ar…/popup/script.min.js?178829006311158

js unionmart.ru collected 2026-10-01 12:36:40 UTC 11,158 bytes, 465 lines download raw bytes

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

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.