PageSourceSearch

https://primemeat.ru/local/templates/primemeat/components/arturgol…/header/script.js?168927531210386

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

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.