PageSourceSearch

https://klimatbox.ru/bitrix/templates/klimatbox/components/bitrix/search.title/store/script.js?1401195639

js klimatbox.ru collected 2026-10-06 02:04:30 UTC 8,517 bytes, 337 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.currentRow = -1;
21	this.RESULT = null;
22	this.CONTAINER = null;
23	this.INPUT = null;
24	this.WAIT = null;
25
26	this.ShowResult = function(result)
27	{
28		var pos = BX.pos(_this.CONTAINER);
29		pos.width = pos.right - pos.left;
30		_this.RESULT.style.position = 'absolute';
31		_this.RESULT.style.top = (pos.bottom + 2) + 'px';
32		_this.RESULT.style.left = pos.left + 'px';
33		_this.RESULT.style.width = pos.width + 'px';
34		if(result != null)
35			_this.RESULT.innerHTML = result;
36
37		if(_this.RESULT.innerHTML.length > 0)
38			_this.RESULT.style.display = 'block';
39		else
40			_this.RESULT.style.display = 'none';
41
42		//ajust left column to be an outline
43		var th;
44		var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true);
45		if(tbl) th = BX.findChild(tbl, {'tag':'th'}, true);
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+100)+ '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			var 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 cnt = tbl.rows.length;
93
94		switch (keyCode)
95		{
96		case 27: // escape key - close search div
97			_this.RESULT.style.display = 'none';
98			_this.currentRow = -1;
99			_this.UnSelectAll();
100		return true;
101
102		case 40: // down key - navigate down on search results
103			if(_this.RESULT.style.display == 'none')
104				_this.RESULT.style.display = 'block';
105
106			var first = -1;
107			for(var i = 0; i < cnt; i++)
108			{
109				if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
110				{
111					if(first == -1)
112						first = i;
113
114					if(_this.currentRow < i)
115					{
116						_this.currentRow = i;
117						break;
118					}
119					else if(tbl.rows[i].className == 'title-search-selected')
120					{
121						tbl.rows[i].className = '';
122					}
123				}
124			}
125
126			if(i == cnt && _this.currentRow != i)
127				_this.currentRow = first;
128
129			tbl.rows[_this.currentRow].className = 'title-search-selected';
130		return true;
131
132		case 38: // up key - navigate up on search results
133			if(_this.RESULT.style.display == 'none')
134				_this.RESULT.style.display = 'block';
135
136			var last = -1;
137			for(var i = cnt-1; i >= 0; i--)
138			{
139				if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
140				{
141					if(last == -1)
142						last = i;
143
144					if(_this.currentRow > i)
145					{
146						_this.currentRow = i;
147						break;
148					}
149					else if(tbl.rows[i].className == 'title-search-selected')
150					{
151						tbl.rows[i].className = '';
152					}
153				}
154			}
155
156			if(i < 0 && _this.currentRow != i)
157				_this.currentRow = last;
158
159			tbl.rows[_this.currentRow].className = 'title-search-selected';
160		return true;
161
162		case 13: // enter key - choose current search result
163			if(_this.RESULT.style.display == 'block')
164			{
165				for(var i = 0; i < cnt; i++)
166				{
167					if(_this.currentRow == i)
168					{
169						if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
170						{
171							var a = BX.findChild(tbl.rows[i], {'tag':'a'}, true);
172							if(a)
173							{
174								window.location = a.href;
175								return true;
176							}
177						}
178					}
179				}
180			}
181		return false;
182		}
183
184		return false;
185	}
186
187	this.onTimeout = function()
188	{
189		if(_this.INPUT.value != _this.oldValue && _this.INPUT.value != _this.startText)
190		{
191			if(_this.INPUT.value.length >= _this.arParams.MIN_QUERY_LEN)
192			{
193				_this.cache_key = _this.oldValue = _this.INPUT.value;
194				if(_this.cache[_this.cache_key] == null)
195				{
196					if(_this.WAIT)
197					{
198						var pos = BX.pos(_this.INPUT);
199						var height = (pos.bottom - pos.top)-2;
200						_this.WAIT.style.top = (pos.top+1) + 'px';
201						_this.WAIT.style.height = height + 'px';
202						_this.WAIT.style.width = height + 'px';
203						_this.WAIT.style.left = (pos.right - height + 2) + 'px';
204						_this.WAIT.style.display = 'block';
205					}
206
207					BX.ajax.post(
208						_this.arParams.AJAX_PAGE,
209						{
210							'ajax_call':'y',
211							'q':_this.INPUT.value
212						},
213						function(result)
214						{
215							_this.cache[_this.cache_key] = result;
216							_this.ShowResult(result);
217							_this.currentRow = -1;
218							_this.EnableMouseEvents();
219							if(_this.WAIT)
220								_this.WAIT.style.display = 'none';
221							setTimeout(_this.onTimeout, 500);
222						}
223					);
224				}
225				else
226				{
227					_this.ShowResult(_this.cache[_this.cache_key]);
228					_this.currentRow = -1;
229					_this.EnableMouseEvents();
230					setTimeout(_this.onTimeout, 500);
231				}
232			}
233			else
234			{
235				_this.RESULT.style.display = 'none';
236				_this.currentRow = -1;
237				_this.UnSelectAll();
238				setTimeout(_this.onTimeout, 500);
239			}
240		}
241		else
242		{
243			setTimeout(_this.onTimeout, 500);
244		}
245	}
246
247	this.UnSelectAll = function()
248	{
249		var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true);
250		if(tbl)
251		{
252			var cnt = tbl.rows.length;
253			for(var i = 0; i < cnt; i++)
254				tbl.rows[i].className = '';
255		}
256	}
257
258	this.EnableMouseEvents = function()
259	{
260		var tbl = BX.findChild(_this.RESULT, {'tag':'table','class':'title-search-result'}, true);
261		if(tbl)
262		{
263			var cnt = tbl.rows.length;
264			for(var i = 0; i < cnt; i++)
265				if(!BX.findChild(tbl.rows[i], {'class':'title-search-separator'}, true))
266				{
267					tbl.rows[i].id = 'row_' + i;
268					tbl.rows[i].onmouseover = function (e) {
269						if(_this.currentRow != this.id.substr(4))
270						{
271							_this.UnSelectAll();
272							this.className = 'title-search-selected';
273							_this.currentRow = this.id.substr(4);
274						}
275					};
276					tbl.rows[i].onmouseout = function (e) {
277						this.className = '';
278						_this.currentRow = -1;
279					};
280				}
281		}
282	}
283
284	this.onFocusLost = function(hide)
285	{
286		setTimeout(function(){_this.RESULT.style.display = 'none';}, 250);
287	}
288
289	this.onFocusGain = function()
290	{
291		if(_this.RESULT.innerHTML.length)
292			_this.ShowResult();
293	}
294
295	this.onKeyDown = function(e)
296	{
297		if(!e)
298			e = window.event;
299
300		if (_this.RESULT.style.display == 'block')
301		{
302			if(_this.onKeyPress(e.keyCode))
303				return BX.PreventDefault(e);
304		}
305	}
306
307	this.Init = function()
308	{
309		this.CONTAINER = document.getElementById(this.arParams.CONTAINER_ID);
310		this.RESULT = document.body.appendChild(document.createElement("DIV"));
311		this.RESULT.className = 'title-search-result';
312		this.INPUT = document.getElementById(this.arParams.INPUT_ID);
313		this.startText = this.oldValue = this.INPUT.value;
314		BX.bind(this.INPUT, 'focus', function() {_this.onFocusGain()});
315		BX.bind(this.INPUT, 'blur', function() {_this.onFocusLost()});
316
317		if(BX.browser.IsSafari() || BX.browser.IsIE())
318			this.INPUT.onkeydown = this.onKeyDown;
319		else
320			this.INPUT.onkeypress = this.onKeyDown;
321
322		if(this.arParams.WAIT_IMAGE)
323		{
324			this.WAIT = document.body.appendChild(document.createElement("DIV"));
325			this.WAIT.style.backgroundImage = "url('" + this.arParams.WAIT_IMAGE + "')";
326			if(!BX.browser.IsIE())
327				this.WAIT.style.backgroundRepeat = 'none';
328			this.WAIT.style.display = 'none';
329			this.WAIT.style.position = 'absolute';
330			this.WAIT.style.zIndex = '1100';
331		}
332
333		setTimeout(this.onTimeout, 500);
334	}
335
336	BX.ready(function (){_this.Init(arParams)});
337}

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.