PageSourceSearch

https://xn--80aaigaklutmw7el2i.xn--p1ai/bitrix/components/bitrix/s…/templates/.default/script.js

js xn--80aaigaklutmw7el2i.xn--p1ai collected 2026-10-08 16:31:12 UTC 11,539 bytes, 433 lines download raw bytes

1BX.namespace('BX.Sale.component.location.selector');
2
3if(typeof BX.Sale.component.location.selector.search == 'undefined' && typeof BX.ui != 'undefined' && typeof BX.ui.widget != 'undefined'){
4
5	BX.Sale.component.location.selector.search = function(opts, nf){
6
7		this.parentConstruct(BX.Sale.component.location.selector.search, opts);
8
9		BX.merge(this, {
10			opts: {
11
12				usePagingOnScroll: 		true,
13				pageSize: 				10,
14				//scrollThrottleTimeout: 	100,
15				arrowScrollAdditional: 	2,
16				pageUpWardOffset: 		3,
17				provideLinkBy: 			'id',
18
19				bindEvents: {
20
21					'after-input-value-modify': function(){
22
23						this.ctrls.fullRoute.value = '';
24
25					},
26					'after-select-item': function(itemId){
27
28						var so = this.opts;
29						var cItem = this.vars.cache.nodes[itemId];
30
31						var path = cItem.DISPLAY;
32						if(typeof cItem.PATH == 'object'){
33							for(var i = 0; i < cItem.PATH.length; i++){
34								path += ', '+this.vars.cache.path[cItem.PATH[i]]; // deprecated
35							}
36						}
37
38						this.ctrls.inputs.fake.setAttribute('title', path);
39						this.ctrls.fullRoute.value = path;
40
41						if(typeof this.opts.callback == 'string' && this.opts.callback.length > 0 && this.opts.callback in window)
42							window[this.opts.callback].apply(this, [itemId, this]);
43					},
44					'after-deselect-item': function(){
45						this.ctrls.fullRoute.value = '';
46						this.ctrls.inputs.fake.setAttribute('title', '');
47					},
48					'before-render-variant': function(itemData){
49
50						if(itemData.PATH.length > 0){
51							var path = '';
52							for(var i = 0; i < itemData.PATH.length; i++)
53								path += ', '+this.vars.cache.path[itemData.PATH[i]];
54
55							itemData.PATH = path;
56						}else
57							itemData.PATH = '';
58
59						var query = '';
60
61						if(this.vars && this.vars.lastQuery && this.vars.lastQuery.QUERY)
62							query = this.vars.lastQuery.QUERY;
63
64						if(BX.type.isNotEmptyString(query)){
65							var chunks = [];
66							if(this.opts.wrapSeparate)
67								chunks = query.split(/\s+/);
68							else
69								chunks = [query];
70
71							itemData['=display_wrapped'] = BX.util.wrapSubstring(itemData.DISPLAY+itemData.PATH, chunks, this.opts.wrapTagName, true);
72						}else
73							itemData['=display_wrapped'] = BX.util.htmlspecialchars(itemData.DISPLAY);
74
75						itemData['=id'] = BX.util.htmlspecialchars(itemData.VALUE);
76					}
77				}
78			},
79			vars: {
80				cache: {
81					path: 			{},
82					nodesByCode: 	{}
83				}
84			},
85			sys: {
86				code: 'sls'
87			}
88		});
89
90		this.handleInitStack(nf, BX.Sale.component.location.selector.search, opts);
91	}
92	BX.extend(BX.Sale.component.location.selector.search, BX.ui.autoComplete);
93	BX.merge(BX.Sale.component.location.selector.search.prototype, {
94
95		// member of stack of initializers, must be defined even if do nothing
96		init: function(){
97
98			// deprecated begin
99			if(typeof this.opts.pathNames == 'object')
100				BX.merge(this.vars.cache.path, this.opts.pathNames);
101			// deprecated end
102
103			this.pushFuncStack('buildUpDOM', BX.Sale.component.location.selector.search);
104			this.pushFuncStack('bindEvents', BX.Sale.component.location.selector.search);
105		},
106
107		buildUpDOM: function(){
108
109			var sc = this.ctrls,
110				so = this.opts,
111				sv = this.vars,
112				ctx = this,
113				code = this.sys.code;
114
115			// full route node
116			sc.fullRoute = BX.create('input', {
117				props: {
118					className: 'bx-ui-'+code+'-route'
119				},
120				attrs: {
121					type: 'text',
122					disabled: 'disabled',
123					autocomplete: 'off'
124				}
125			});
126
127			// todo: use metrics instead!
128			BX.style(sc.fullRoute, 'paddingTop', BX.style(sc.inputs.fake, 'paddingTop'));
129			BX.style(sc.fullRoute, 'paddingLeft', BX.style(sc.inputs.fake, 'paddingLeft'));
130			BX.style(sc.fullRoute, 'paddingRight', '0px');
131			BX.style(sc.fullRoute, 'paddingBottom', '0px');
132
133			BX.style(sc.fullRoute, 'marginTop', BX.style(sc.inputs.fake, 'marginTop'));
134			BX.style(sc.fullRoute, 'marginLeft', BX.style(sc.inputs.fake, 'marginLeft'));
135			BX.style(sc.fullRoute, 'marginRight', '0px');
136			BX.style(sc.fullRoute, 'marginBottom', '0px');
137
138			if(BX.style(sc.inputs.fake, 'borderTopStyle') != 'none'){
139				BX.style(sc.fullRoute, 'borderTopStyle', 'solid');
140				BX.style(sc.fullRoute, 'borderTopColor', 'transparent');
141				BX.style(sc.fullRoute, 'borderTopWidth', BX.style(sc.inputs.fake, 'borderTopWidth'));
142			}
143
144			if(BX.style(sc.inputs.fake, 'borderLeftStyle') != 'none'){
145				BX.style(sc.fullRoute, 'borderLeftStyle', 'solid');
146				BX.style(sc.fullRoute, 'borderLeftColor', 'transparent');
147				BX.style(sc.fullRoute, 'borderLeftWidth', BX.style(sc.inputs.fake, 'borderLeftWidth'));
148			}
149
150			BX.prepend(sc.fullRoute, sc.container);
151
152			sc.inputBlock = this.getControl('input-block');
153			sc.loader = this.getControl('loader');
154		},
155
156		bindEvents: function(){
157
158			var ctx = this;
159
160			// quick links
161			BX.bindDelegate(this.getControl('quick-locations', true), 'click', {tag: 'a'}, function(){
162				ctx.setValueByLocationId(BX.data(this, 'id'));
163			});
164
165			this.vars.outSideClickScope = this.ctrls.inputBlock;
166		},
167
168		////////// PUBLIC: free to use outside
169
170		// location id is just a value in terms of autocomplete
171		setValueByLocationId: function(id, autoSelect){
172			BX.Sale.component.location.selector.search.superclass.setValue.apply(this, [id, autoSelect]);
173		},
174
175		setValueByLocationIds: function(locationsData){
176			if(locationsData.IDS)
177			{
178				this.displayPage(
179					{
180						'VALUE': locationsData.IDS,
181						'order': {'TYPE_ID': 'ASC', 'NAME.NAME': 'ASC'}
182					}
183				);
184			}
185		},
186
187		setValueByLocationCode: function(code, autoSelect){
188
189			var sv = this.vars,
190				so = this.opts,
191				sc = this.ctrls,
192				ctx = this;
193
194			this.hideError();
195
196			if(code == null || code == false || typeof code == 'undefined' || code.toString().length == 0){ // deselect
197
198				this.resetVariables();
199
200				BX.cleanNode(sc.vars);
201
202				if(BX.type.isElementNode(sc.nothingFound))
203					BX.hide(sc.nothingFound);
204
205				this.fireEvent('after-deselect-item');
206				this.fireEvent('after-clear-selection');
207
208				return;
209			};
210
211			if(autoSelect !== false)
212				sv.forceSelectSingeOnce = true;
213
214			if(typeof sv.cache.nodesByCode[code] == 'undefined'){
215
216				// lazyload it...
217				this.resetNavVariables();
218
219				ctx.downloadBundle({CODE: code}, function(data){
220
221					ctx.fillCache(data, false); // storing item in the cache
222
223					if(typeof sv.cache.nodesByCode[code] == 'undefined'){ // still not found
224						ctx.showNothingFound();
225					}else{
226
227						var value = sv.cache.nodesByCode[code].VALUE;
228
229						//////////////////
230						if(so.autoSelectIfOneVariant || sv.forceSelectSingeOnce)
231							ctx.selectItem(value);
232						else
233							ctx.displayVariants([value]);
234						//////////////////
235					}
236				}, function(){
237					sv.forceSelectSingeOnce = false;
238				});
239
240			}else{
241
242				var value = sv.cache.nodesByCode[code].VALUE;
243
244				if(sv.forceSelectSingeOnce)
245					this.selectItem(value);
246				else
247					this.displayVariants([value]);
248
249				sv.forceSelectSingeOnce = false;
250			}
251		},
252
253		getNodeByValue: function(value){
254			if(this.opts.provideLinkBy == 'id')
255				return this.vars.cache.nodes[value];
256			else
257				return this.vars.cache.nodesByCode[value];
258		},
259
260		getNodeByLocationId: function(value){
261			return this.vars.cache.nodes[value];
262		},
263
264		setValue: function(value){
265
266			if(this.opts.provideLinkBy == 'id')
267				BX.Sale.component.location.selector.search.superclass.setValue.apply(this, [value]);
268			else
269				this.setValueByLocationCode(value);
270		},
271
272		getValue: function(){
273			if(this.opts.provideLinkBy == 'id')
274				return this.vars.value === false ? '' : this.vars.value;
275			else{
276				return this.vars.value ? this.vars.cache.nodes[this.vars.value].CODE : '';
277			}
278		},
279
280		getSelectedPath: function(){
281
282			var sv = this.vars,
283				result = [];
284
285			if(typeof sv.value == 'undefined' || sv.value == false || sv.value == '')
286				return result;
287
288			if(typeof sv.cache.nodes[sv.value] != 'undefined'){
289				var item = BX.clone(sv.cache.nodes[sv.value]);
290				if(typeof item.TYPE_ID != 'undefined' && typeof this.opts.types != 'undefined')
291					item.TYPE = this.opts.types[item.TYPE_ID].CODE;
292
293				var path = item.PATH;
294				delete(item.PATH);
295				result.push(item);
296
297				if(typeof path != 'undefined'){
298					for(var k in path){
299						var item = BX.clone(sv.cache.nodes[path[k]]);
300						if(typeof item.TYPE_ID != 'undefined' && typeof this.opts.types != 'undefined')
301							item.TYPE = this.opts.types[item.TYPE_ID].CODE;
302
303						delete(item.PATH);
304
305						result.push(item);
306					}
307				}
308			}
309
310			return result;
311		},
312
313		////////// PRIVATE: forbidden to use outside (for compatibility reasons)
314
315		setInitialValue: function(){
316
317			if(this.opts.selectedItem !== false) // there will be always a value as ID, no matter what this.opts.provideLinkBy is equal to
318				this.setValueByLocationId(this.opts.selectedItem);
319			else if(this.ctrls.inputs.origin.value.length > 0) // there colud be eiter ID or CODE
320			{
321				if(this.opts.provideLinkBy == 'id')
322					this.setValueByLocationId(this.ctrls.inputs.origin.value);
323				else
324					this.setValueByLocationCode(this.ctrls.inputs.origin.value);
325			}
326		},
327
328		addItem2Cache: function(item){
329			this.vars.cache.nodes[item.VALUE] = item;
330			this.vars.cache.nodesByCode[item.CODE] = item;
331		},
332
333		refineRequest: function(request){
334
335			var filter = {};
336			if(typeof request['QUERY'] != 'undefined') // search by words
337				filter['=PHRASE'] = request.QUERY;
338
339			if(typeof request['VALUE'] != 'undefined') // search by id
340				filter['=ID'] = request.VALUE;
341
342			if(typeof request['CODE'] != 'undefined') // search by code
343				filter['=CODE'] = request.CODE;
344
345			if(typeof this.opts.query.BEHAVIOUR.LANGUAGE_ID != 'undefined')
346				filter['=NAME.LANGUAGE_ID'] = this.opts.query.BEHAVIOUR.LANGUAGE_ID;
347
348			if(BX.type.isNotEmptyString(this.opts.query.FILTER.SITE_ID))
349				filter['=SITE_ID'] = this.opts.query.FILTER.SITE_ID;
350
351			var result = {
352				'select': {
353					'VALUE': 'ID',
354					'DISPLAY': 'NAME.NAME',
355					'1': 'CODE',
356					'2': 'TYPE_ID'
357				},
358				'additionals': {
359					'1': 'PATH'
360				},
361				'filter': filter,
362				'version': '2'
363			};
364
365			if(typeof request['order'] != 'undefined')
366				result['order'] = request.order;
367
368			return result;
369		},
370
371		refineResponce: function(responce, request){
372
373			if(typeof responce.ETC.PATH_ITEMS != 'undefined')
374			{
375				// deprecated begin
376				for(var k in responce.ETC.PATH_ITEMS){
377					if(BX.type.isNotEmptyString(responce.ETC.PATH_ITEMS[k].DISPLAY))
378						this.vars.cache.path[k] = responce.ETC.PATH_ITEMS[k].DISPLAY;
379				}
380				// deprecated end
381
382				for(var k in responce.ITEMS){
383
384					var item = responce.ITEMS[k];
385
386					if(typeof item.PATH != 'undefined')
387					{
388						var subPath = BX.clone(item.PATH);
389						for(var p in item.PATH)
390						{
391							var pItemId = item.PATH[p];
392
393							subPath.shift();
394							if(typeof this.vars.cache.nodes[pItemId] == 'undefined' && typeof responce.ETC.PATH_ITEMS[pItemId] != 'undefined'){
395
396								var pItem = BX.clone(responce.ETC.PATH_ITEMS[pItemId]);
397								pItem.PATH = BX.clone(subPath);
398								this.vars.cache.nodes[pItemId] = pItem;
399							}
400						}
401					}
402				}
403			}
404
405			return responce.ITEMS;
406		},
407
408		refineItems: function(items){
409			return items;
410		},
411
412		refineItemDataForTemplate: function(itemData){
413			return itemData;
414		},
415
416		// custom value getter (obsolete method)
417		getSelectorValue: function(value){
418
419			if(this.opts.provideLinkBy == 'id')
420				return value;
421
422			if(typeof this.vars.cache.nodes[value] != 'undefined')
423				return this.vars.cache.nodes[value].CODE;
424			else
425				return '';
426		},
427
428		whenLoaderToggle: function(way){
429			BX[way ? 'show' : 'hide'](this.ctrls.loader);
430		}
431
432	});
433}

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.