PageSourceSearch

https://www.bestsafe.ru/bitrix/templates/aspro_max/components/bitrix/search.title/corp/script.js

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

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.