PageSourceSearch

https://xn--90aisff1g.xn--p1ai/local/templates/agency_ux_nobel/components/bitrix/search.title/hints/script.js

js xn--90aisff1g.xn--p1ai collected 2026-10-07 18:01:43 UTC 9,889 bytes, 414 lines download raw bytes

1function JCTitleSearch(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	if(arParams.MIN_QUERY_LEN <= 0)
14		arParams.MIN_QUERY_LEN = 1;
15
16	this.cache = [];
17	this.cache_key = null;
18
19	this.startText = '';
20	this.running = false;
21	this.runningCall = 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		
37		var pos = _this.adjustResultNode();
38
39		//adjust left column to be an outline
40		var res_pos;
41		var th;
42		var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true);
43		if(tbl)
44		{
45			th = BX.findChild(tbl, {'tag':'th'}, true);
46		}
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
89	this.onKeyPress = function(keyCode)
90	{
91
92		var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true);
93		if(!tbl)
94			return false;
95
96		var i;
97		var cnt = tbl.rows.length;
98
99		switch (keyCode)
100		{
101		case 27: // escape key - close search div
102			_this.RESULT.style.display = 'none';
103			_this.currentRow = -1;
104			_this.UnSelectAll();
105		return true;
106
107		case 40: // down key - navigate down on search results
108			if(_this.RESULT.style.display == 'none')
109				_this.RESULT.style.display = 'block';
110
111			var first = -1;
112			for(i = 0; i < cnt; i++)
113			{
114				if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
115				{
116					if(first == -1)
117						first = i;
118
119					if(_this.currentRow < i)
120					{
121						_this.currentRow = i;
122						break;
123					}
124					else if(tbl.rows[i].className == 'title-search-selected')
125					{
126						tbl.rows[i].className = '';
127					}
128				}
129			}
130
131			if(i == cnt && _this.currentRow != i)
132				_this.currentRow = first;
133
134			tbl.rows[_this.currentRow].className = 'title-search-selected';
135		return true;
136
137		case 38: // up key - navigate up on search results
138			if(_this.RESULT.style.display == 'none')
139				_this.RESULT.style.display = 'block';
140
141			var last = -1;
142			for(i = cnt-1; i >= 0; i--)
143			{
144				if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
145				{
146					if(last == -1)
147						last = i;
148
149					if(_this.currentRow > i)
150					{
151						_this.currentRow = i;
152						break;
153					}
154					else if(tbl.rows[i].className == 'title-search-selected')
155					{
156						tbl.rows[i].className = '';
157					}
158				}
159			}
160
161			if(i < 0 && _this.currentRow != i)
162				_this.currentRow = last;
163
164			tbl.rows[_this.currentRow].className = 'title-search-selected';
165		return true;
166
167		case 13: // enter key - choose current search result
168			if(_this.RESULT.style.display == 'block')
169			{
170				for(i = 0; i < cnt; i++)
171				{
172					if(_this.currentRow == i)
173					{
174						if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
175						{
176							var a = BX.findChild(tbl.rows[i], {'tag':'a'}, true);
177							if(a)
178							{
179								window.location = a.href;
180								return true;
181							}
182						}
183					}
184				}
185			}
186		return false;
187		}
188
189		return false;
190	};
191
192	this.onTimeout = function()
193	{
194		_this.onChange(function(){
195			setTimeout(_this.onTimeout, 500);
196		});
197	};
198
199	this.onInput = function()
200	{
201		_this.onInput(function(){
202			console.log(_this.RESULT)
203		});
204	};
205	// custom  AGAIN
206
207	console.log(this.INPUT)
208	// this.INPUT.addEventListener('input', function() {
209
210	// });
211
212	this.onChange = function(callback)
213	
214	{
215		if (_this.running)
216		{
217			_this.runningCall = true;
218			return;
219		}
220		_this.running = true;
221
222		if(_this.INPUT.value != _this.oldValue && _this.INPUT.value != _this.startText)
223		{
224			_this.oldValue = _this.INPUT.value;
225			if(_this.INPUT.value.length >= _this.arParams.MIN_QUERY_LEN)
226			{
227				_this.cache_key = _this.arParams.INPUT_ID + '|' + _this.INPUT.value;
228				if(_this.cache[_this.cache_key] == null)
229				{
230					if(_this.WAIT)
231					{
232						var pos = BX.pos(_this.INPUT);
233						var height = (pos.bottom - pos.top)-2;
234						_this.WAIT.style.top = (pos.top+1) + 'px';
235						_this.WAIT.style.height = height + 'px';
236						_this.WAIT.style.width = height + 'px';
237						_this.WAIT.style.left = (pos.right - height + 2) + 'px';
238						_this.WAIT.style.display = 'block';
239					}
240
241					BX.ajax.post(
242						_this.arParams.AJAX_PAGE,
243						{
244							'ajax_call':'y',
245							'INPUT_ID':_this.arParams.INPUT_ID,
246							'q':_this.INPUT.value,
247							'l':_this.arParams.MIN_QUERY_LEN
248						},
249						function(result)
250						{
251							_this.cache[_this.cache_key] = result;
252							_this.ShowResult(result);
253							_this.currentRow = -1;
254							_this.EnableMouseEvents();
255							if (!!callback)
256								callback();
257							_this.running = false;
258							if (_this.runningCall)
259							{
260								_this.runningCall = false;
261								_this.onChange();
262							}
263						}
264					);
265					return;
266				}
267				else
268				{
269					_this.ShowResult(_this.cache[_this.cache_key]);
270					_this.currentRow = -1;
271					_this.EnableMouseEvents();
272				}
273			}
274			else
275			{
276				_this.RESULT.style.display = 'none';
277				_this.currentRow = -1;
278				_this.UnSelectAll();
279			}
280		}
281		if (!!callback)
282			callback();
283		_this.running = false;
284	};
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
325
326	this.onFocusGain = function()
327	{
328		if(_this.RESULT.innerHTML.length)
329			_this.ShowResult();
330	};
331
332	this.onKeyDown = function(e)
333	{
334		let failBlock = document.querySelector(".fail-search")
335		let popularBlock = document.querySelector(".popular-search")
336		console.log(_this.RESULT)
337		if (_this.RESULT.style.display == 'none') {
338			popularBlock.style.display = "block"
339		}else{
340			popularBlock.style.display = "none"
341		}
342		if(!e)
343			e = window.event;
344
345		if (_this.RESULT.style.display == 'block')
346		{
347			if(_this.onKeyPress(e.keyCode))
348				return BX.PreventDefault(e);
349		}
350	};
351
352	this.adjustResultNode = function()
353	{
354		if(!(BX.type.isElementNode(_this.RESULT)
355			&& BX.type.isElementNode(_this.CONTAINER))
356		)
357		{
358			return { top: 0, right: 0, bottom: 0, left: 0, width: 0, height: 0 };
359		}
360
361		var pos = BX.pos(_this.CONTAINER);
362
363
364		// custom stuff
365		let container = document.getElementById(this.arParams.CONTAINER_ID)
366		_this.RESULT.style.width = '100%';
367		container.appendChild(_this.RESULT)
368		return pos;
369		// 
370	};
371
372	this._onContainerLayoutChange = function()
373	{
374		if(BX.type.isElementNode(_this.RESULT)
375			&& _this.RESULT.style.display !== "none"
376			&& _this.RESULT.innerHTML !== ''
377		)
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 = document.body.appendChild(document.createElement("DIV"));
388		this.RESULT.className = 'title-search-result';
389		this.INPUT = document.getElementById(this.arParams.INPUT_ID);
390		this.startText = this.oldValue = this.INPUT.value;
391		BX.bind(this.INPUT, 'focus', function() {_this.onFocusGain()});
392		this.INPUT.onkeydown = this.onKeyDown;
393
394		if(this.arParams.WAIT_IMAGE)
395		{
396			this.WAIT = document.body.appendChild(document.createElement("DIV"));
397			this.WAIT.style.backgroundImage = "url('" + this.arParams.WAIT_IMAGE + "')";
398			if(!BX.browser.IsIE())
399				this.WAIT.style.backgroundRepeat = 'none';
400			this.WAIT.style.display = 'none';
401			this.WAIT.style.position = 'absolute';
402			this.WAIT.style.zIndex = '1100';
403		}
404
405		BX.bind(this.INPUT, 'bxchange', function() {_this.onChange()});
406
407		var fixedParent = BX.findParent(this.CONTAINER, BX.is_fixed);
408		if(BX.type.isElementNode(fixedParent))
409		{
410			BX.bind(window, 'scroll', BX.throttle(this.onScroll, 100, this));
411		}
412	};
413	BX.ready(function (){_this.Init(arParams)});
414}

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.