PageSourceSearch

https://colorformula.by/bitrix/templates/aspro_max_colorformula/co…/corp/script.js?178224454711270

js colorformula.by collected 2026-10-07 15:36:11 UTC 11,270 bytes, 457 lines download raw bytes

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

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.