PageSourceSearch

https://izdatsovet.ru/bitrix/cache/js/b1/easterx_copy_copy_copy/pa…183441c04e80deeb5f0bb1f4.js?179036757812905

js izdatsovet.ru collected 2026-09-25 21:51:48 UTC 12,905 bytes, 584 lines download raw bytes

1
2; /* Start:"a:4:{s:4:"full";s:100:"/bitrix/templates/.default/components/bitrix/search.suggest.input/.default/script.js?154868624412503";s:6:"source";s:84:"/bitrix/templates/.default/components/bitrix/search.suggest.input/.default/script.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/
3function JsSuggest(oHandler, sParams, sParser)
4{
5	var t = this;
6
7	t.oObj = oHandler;
8	t.sParams = sParams;
9	// Arrays for data
10	if (sParser)
11	{
12		t.sExp = new RegExp("["+sParser+"]+", "i");
13	}
14	else
15	{
16		t.sExp = new RegExp(",");
17	}
18	t.oLast = {"str":false, "arr":false};
19	t.oThis = {"str":false, "arr":false};
20	t.oEl = {"start":false, "end":false};
21	t.oUnfinedWords = {};
22	// Flags
23	t.bReady = true;
24	t.eFocus = true;
25	// Array with results & it`s showing
26	t.aDiv = null;
27	t.oDiv = null;
28	// Pointers
29	t.oActive = null;
30	t.oPointer = [];
31	t.oPointer_default = [];
32	t.oPointer_this = 'input_field';
33
34	t.oObj.onblur = function()
35	{
36		t.eFocus = false;
37	};
38
39	t.oObj.onfocus = function()
40	{
41		if (!t.eFocus)
42		{
43			t.eFocus = true;
44			setTimeout(function(){t.CheckModif('focus')}, 500);
45		}
46	};
47
48	t.oLast["arr"] = t.oObj.value.split(t.sExp);
49	t.oLast["str"] = t.oLast["arr"].join(":");
50
51	setTimeout(function(){t.CheckModif('this')}, 500);
52
53	this.CheckModif = function(__data)
54	{
55		var
56			sThis = false, tmp = 0,
57			bUnfined = false, word = "",
58			cursor = {};
59
60		if (!t.eFocus)
61			return;
62
63		if (t.bReady && t.oObj.value.length > 0)
64		{
65			// Preparing input data
66			t.oThis["arr"] = t.oObj.value.split(t.sExp);
67			t.oThis["str"] = t.oThis["arr"].join(":");
68
69			// Getting modificated element
70			if (t.oThis["str"] && (t.oThis["str"] != t.oLast["str"]))
71			{
72				cursor['position'] = TCJsUtils.getCursorPosition(t.oObj);
73				if (cursor['position']['end'] > 0 && !t.sExp.test(t.oObj.value.substr(cursor['position']['end']-1, 1)))
74				{
75					cursor['arr'] = t.oObj.value.substr(0, cursor['position']['end']).split(t.sExp);
76					sThis = t.oThis["arr"][cursor['arr'].length - 1];
77
78					t.oEl['start'] = cursor['position']['end'] - cursor['arr'][cursor['arr'].length - 1].length;
79					t.oEl['end'] = t.oEl['start'] + sThis.length;
80					t.oEl['content'] = sThis;
81
82					t.oLast["arr"] = t.oThis["arr"];
83					t.oLast["str"] = t.oThis["str"];
84				}
85			}
86			if (sThis)
87			{
88				// Checking for UnfinedWords
89				for (tmp = 2; tmp <= sThis.length; tmp++)
90				{
91					word = sThis.substr(0, tmp);
92					if (t.oUnfinedWords[word] == '!fined')
93					{
94						bUnfined = true;
95						break;
96					}
97				}
98				if (!bUnfined)
99					t.Send(sThis);
100			}
101		}
102		setTimeout(function(){t.CheckModif('this')}, 500);
103	};
104
105	t.Send = function(sSearch)
106	{
107		if (!sSearch)
108			return false;
109
110		var oError = [];
111		t.bReady = false;
112		if (BX('wait_container'))
113		{
114			BX('wait_container').innerHTML = BX.message('JS_CORE_LOADING');
115			BX.show(BX('wait_container'));
116		}
117		BX.ajax.post(
118			'/bitrix/components/bitrix/search.suggest.input/search.php',
119			{"search":sSearch, "params":t.sParams},
120			function(data)
121			{
122				var result = {};
123				t.bReady = true;
124
125				try
126				{
127					eval("result = " + data + ";");
128				}
129				catch(e)
130				{
131					oError['result_unval'] = e;
132				}
133
134				if (TCJsUtils.empty(result))
135					oError['result_empty'] = 'Empty result';
136
137				try
138				{
139					if (TCJsUtils.empty(oError) && (typeof result == 'object'))
140					{
141						if (!(result.length == 1 && result[0]['NAME'] == t.oEl['content']))
142						{
143							t.Show(result);
144							return;
145						}
146					}
147					else
148					{
149						t.oUnfinedWords[t.oEl['content']] = '!fined';
150					}
151				}
152				catch(e)
153				{
154					oError['unknown_error'] = e;
155				}
156
157				if(BX('wait_container'))
158					BX.hide(BX('wait_container'));
159			}
160		);
161	};
162
163	t.Show = function(result)
164	{
165		t.Destroy();
166		t.oDiv = document.body.appendChild(document.createElement("DIV"));
167		t.oDiv.id = t.oObj.id+'_div';
168
169		t.oDiv.className = "search-popup";
170		t.oDiv.style.position = 'absolute';
171
172		t.aDiv = t.Print(result);
173		var pos = TCJsUtils.GetRealPos(t.oObj);
174		t.oDiv.style.width = parseInt(pos["width"]) + "px";
175		TCJsUtils.show(t.oDiv, pos["left"], pos["bottom"]);
176		TCJsUtils.addEvent(document, "click", t.CheckMouse);
177		TCJsUtils.addEvent(document, "keydown", t.CheckKeyword);
178	};
179
180	t.Print = function(aArr)
181	{
182		var aEl = null;
183		var aResult = {};
184		var iCnt = 0;
185		var oDiv = null;
186		var oSpan = null;
187		var sPrefix = t.oDiv.id;
188
189		for (var tmp_ in aArr)
190		{
191			if (aArr.hasOwnProperty(tmp_))
192			{
193				// Math
194				aEl = aArr[tmp_];
195
196				var aRes = {};
197				aRes['ID'] = (aEl['ID'] && aEl['ID'].length > 0) ? aEl['ID'] : iCnt++;
198				aRes['GID'] = sPrefix + '_' + aRes['ID'];
199				aRes['NAME'] = TCJsUtils.htmlspecialcharsEx(aEl['NAME']);
200				aRes['CNT'] = aEl['CNT'];
201
202				aResult[aRes['GID']] = aRes;
203				t.oPointer.push(aRes['GID']);
204				// Graph
205				oDiv = t.oDiv.appendChild(document.createElement("DIV"));
206				oDiv.id = aRes['GID'];
207				oDiv.name = sPrefix + '_div';
208
209				oDiv.className = 'search-popup-row';
210
211				oDiv.onmouseover = function(){t.Init(); this.className='search-popup-row-active';};
212				oDiv.onmouseout = function(){t.Init(); this.className='search-popup-row';};
213				oDiv.onclick = function(){t.oActive = this.id};
214
215				oSpan = oDiv.appendChild(document.createElement("DIV"));
216				oSpan.id = oDiv.id + '_NAME';
217				oSpan.className = "search-popup-el search-popup-el-cnt";
218				oSpan.innerHTML = aRes['CNT'];
219
220				oSpan = oDiv.appendChild(document.createElement("DIV"));
221				oSpan.id = oDiv.id + '_NAME';
222				oSpan.className = "search-popup-el search-popup-el-name";
223				oSpan.innerHTML = aRes['NAME'];
224			}
225		}
226		t.oPointer.push('input_field');
227		t.oPointer_default = t.oPointer;
228		return aResult;
229	};
230
231	t.Destroy = function()
232	{
233		try
234		{
235			TCJsUtils.hide(t.oDiv);
236			t.oDiv.parentNode.removeChild(t.oDiv);
237		}
238		catch(e)
239		{}
240
241		t.aDiv = [];
242		t.oPointer = [];
243		t.oPointer_default = [];
244		t.oPointer_this = 'input_field';
245		t.bReady = true;
246		t.eFocus = true;
247		t.oActive = null;
248
249		TCJsUtils.removeEvent(document, "click", t.CheckMouse);
250		TCJsUtils.removeEvent(document, "keydown", t.CheckKeyword);
251	};
252
253	t.Replace = function()
254	{
255		if (typeof t.oActive == 'string')
256		{
257			var tmp = t.aDiv[t.oActive];
258			var tmp1 = '';
259			if (typeof tmp == 'object')
260			{
261				var elEntities = document.createElement("span");
262				elEntities.innerHTML = tmp['NAME'].replace(/&quot;/g, '"').replace(/&amp;/g, '&');
263				tmp1 = elEntities.innerHTML;
264			}
265			//this preserves leading spaces
266			var start = t.oEl['start'];
267			while(start < t.oObj.value.length && t.oObj.value.substring(start, start+1) == " ")
268				start++;
269
270			t.oObj.value = t.oObj.value.substring(0, start) + tmp1.replace(/&lt;/g, '<').replace(/&gt;/g, '>') + t.oObj.value.substr(t.oEl['end']);
271			TCJsUtils.setCursorPosition(t.oObj, start + tmp1.length);
272		}
273	};
274
275	t.Init = function()
276	{
277		t.oActive = false;
278		t.oPointer = t.oPointer_default;
279		t.Clear();
280		t.oPointer_this = 'input_pointer';
281	};
282
283	t.Clear = function()
284	{
285		var oEl = t.oDiv.getElementsByTagName("div");
286		if (oEl.length > 0 && typeof oEl == 'object')
287		{
288			for (var ii in oEl)
289			{
290				if (oEl.hasOwnProperty(ii))
291				{
292					var oE = oEl[ii];
293					if (oE && (typeof oE == 'object') && (oE.name == t.oDiv.id + '_div'))
294					{
295						oE.className = "search-popup-row";
296					}
297				}
298			}
299		}
300	};
301
302	t.CheckMouse = function()
303	{
304		t.Replace();
305		t.Destroy();
306	};
307
308	t.CheckKeyword = function(e)
309	{
310		if (!e)
311			e = window.event;
312
313		var oP = null;
314		var oEl = null;
315
316		if ((37 < e.keyCode && e.keyCode <41) || (e.keyCode == 13))
317		{
318			t.Clear();
319
320			switch (e.keyCode)
321			{
322				case 38:
323					oP = t.oPointer.pop();
324					if (t.oPointer_this == oP)
325					{
326						t.oPointer.unshift(oP);
327						oP = t.oPointer.pop();
328					}
329
330					if (oP != 'input_field')
331					{
332						t.oActive = oP;
333						oEl = document.getElementById(oP);
334						if (typeof oEl == 'object')
335						{
336							oEl.className = "search-popup-row-active";
337						}
338					}
339					t.oPointer.unshift(oP);
340					break;
341				case 40:
342					oP = t.oPointer.shift();
343					if (t.oPointer_this == oP)
344					{
345						t.oPointer.push(oP);
346						oP = t.oPointer.shift();
347					}
348					if (oP != 'input_field')
349					{
350						t.oActive = oP;
351						oEl = document.getElementById(oP);
352						if (typeof oEl == 'object')
353						{
354							oEl.className = "search-popup-row-active";
355						}
356					}
357					t.oPointer.push(oP);
358					break;
359				case 39:
360					t.Replace();
361					t.Destroy();
362					break;
363				case 13:
364					t.Replace();
365					t.Destroy();
366					break;
367			}
368			t.oPointer_this = oP;
369		}
370		else
371		{
372			t.Destroy();
373		}
374	};
375}
376
377var TCJsUtils =
378{
379	arEvents: [],
380
381	addEvent: function(el, evname, func)
382	{
383		if(el.attachEvent) // IE
384			el.attachEvent("on" + evname, func);
385		else if(el.addEventListener) // Gecko / W3C
386			el.addEventListener(evname, func, false);
387		else
388			el["on" + evname] = func;
389		this.arEvents[this.arEvents.length] = {'element': el, 'event': evname, 'fn': func};
390	},
391
392	removeEvent: function(el, evname, func)
393	{
394		if(el.detachEvent) // IE
395			el.detachEvent("on" + evname, func);
396		else if(el.removeEventListener) // Gecko / W3C
397			el.removeEventListener(evname, func, false);
398		else
399			el["on" + evname] = null;
400	},
401
402	getCursorPosition: function(oObj)
403	{
404		var result = {'start': 0, 'end': 0};
405		if (!oObj || (typeof oObj != 'object'))
406			return result;
407		try
408		{
409			if (document.selection != null && oObj.selectionStart == null)
410			{
411				oObj.focus();
412				var oRange = document.selection.createRange();
413				var oParent = oRange.parentElement();
414				var sBookmark = oRange.getBookmark();
415				var sContents = oObj.value;
416				var sContents_ = oObj.value;
417				var sMarker = '__' + Math.random() + '__';
418
419				while(sContents.indexOf(sMarker) != -1)
420				{
421					sMarker = '__' + Math.random() + '__';
422				}
423
424				if (!oParent || oParent == null || (oParent.type != "textarea" && oParent.type != "text"))
425				{
426					return result;
427				}
428
429				oRange.text = sMarker + oRange.text + sMarker;
430				sContents = oObj.value;
431				result['start'] = sContents.indexOf(sMarker);
432				sContents = sContents.replace(sMarker, "");
433				result['end'] = sContents.indexOf(sMarker);
434				oObj.value = sContents_;
435				oRange.moveToBookmark(sBookmark);
436				oRange.select();
437				return result;
438			}
439			else
440			{
441				return {
442					'start': oObj.selectionStart,
443					'end': oObj.selectionEnd
444				};
445			}
446		}
447		catch(e){}
448		return result;
449	},
450
451	setCursorPosition: function(oObj, iPosition)
452	{
453		if (typeof oObj != 'object')
454			return false;
455
456		oObj.focus();
457
458		try
459		{
460			if (document.selection != null && oObj.selectionStart == null)
461			{
462				var oRange = document.selection.createRange();
463				oRange.select();
464			}
465			else
466			{
467				oObj.selectionStart = iPosition;
468				oObj.selectionEnd = iPosition;
469			}
470			return true;
471		}
472		catch(e)
473		{
474			return false;
475		}
476
477	},
478
479	printArray: function (oObj, sParser, iLevel)
480	{
481		try
482		{
483			var result = '';
484			var space = '';
485
486			if (iLevel==undefined)
487				iLevel = 0;
488			if (!sParser)
489				sParser = "\n";
490
491			for (var j = 0; j <= iLevel; j++)
492				space += '  ';
493
494			for (var i in oObj)
495			{
496				if (oObj.hasOwnProperty(i))
497				{
498					if (typeof oObj[i] == 'object')
499						result += space+i + " = {"+ sParser + TCJsUtils.printArray(oObj[i], sParser, iLevel+1) + ", " + sParser + "}" + sParser;
500					else
501						result += space+i + " = " + oObj[i] + "; " + sParser;
502				}
503			}
504
505			return result;
506		}
507		catch(e)
508		{
509		}
510	},
511
512	empty: function(oObj)
513	{
514		var result = true;
515		if (oObj)
516		{
517			for (var i in oObj)
518			{
519				if (oObj.hasOwnProperty(i))
520				{
521					result = false;
522					break;
523				}
524			}
525		}
526		return result;
527	},
528
529	show: function(oDiv, iLeft, iTop)
530	{
531		if (typeof oDiv != 'object')
532			return;
533		var zIndex = parseInt(oDiv.style.zIndex);
534		if(zIndex <= 0 || isNaN(zIndex))
535			zIndex = 100;
536		oDiv.style.zIndex = zIndex;
537		oDiv.style.left = iLeft + "px";
538		oDiv.style.top = iTop + "px";
539
540		return oDiv;
541	},
542
543	hide: function(oDiv)
544	{
545		if(oDiv)
546			oDiv.style.display = 'none';
547	},
548
549	GetRealPos: function(el)
550	{
551		if(!el || !el.offsetParent)
552			return false;
553
554		var res = {};
555		var objParent = el.offsetParent;
556		res["left"] = el.offsetLeft;
557		res["top"] = el.offsetTop;
558		while(objParent && objParent.tagName != "BODY")
559		{
560			res["left"] += objParent.offsetLeft;
561			res["top"] += objParent.offsetTop;
562			objParent = objParent.offsetParent;
563		}
564		res["right"]=res["left"] + el.offsetWidth;
565		res["bottom"]=res["top"] + el.offsetHeight;
566		res["width"]=el.offsetWidth;
567		res["height"]=el.offsetHeight;
568
569		return res;
570	},
571
572	htmlspecialcharsEx: function(str)
573	{
574		return str.replace(/&amp;/g, '&amp;amp;').replace(/&lt;/g, '&amp;lt;').replace(/&gt;/g, '&amp;gt;').replace(/&quot;/g, '&amp;quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
575	},
576
577	htmlspecialcharsback: function(str)
578	{
579		return str.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
580	}
581};
582
583/* End */
584;; /* /bitrix/templates/.default/components/bitrix/search.suggest.input/.default/script.js?154868624412503*/

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.