PageSourceSearch

https://antenna1.ru/local/templates/aspro_next/components/bitrix/search.title/fixed/script.js

js antenna1.ru collected 2026-10-08 14:09:19 UTC 9,910 bytes, 393 lines download raw bytes

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

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.