PageSourceSearch

https://korshop.ru/bitrix/templates/profood_new/components/bitrix/…/inheader/script.js?148220957710306

js korshop.ru collected 2026-10-02 05:01:09 UTC 10,306 bytes, 415 lines download raw bytes

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

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.