PageSourceSearch

https://drivemotors.by/local/templates/drive2022/components/bitrix…/.default/script.js?167602996014463

js drivemotors.by collected 2026-10-07 00:02:56 UTC 14,463 bytes, 419 lines download raw bytes

1;(function(){
2	var BX = window.BX;
3	if (BX["MFInput"])
4		return;
5	var repo = {},
6		uploader = (function(){
7		var d = function(params) {
8			try {
9				this.params = params;
10				this.controller = BX("mfi-" + params.controlId);
11				this.button = BX("mfi-" + params.controlId + "-button");
12				this.editor = null;
13				if(BX("mfi-" + params.controlId + "-editor")) {
14					this.editor = new BX.AvatarEditor({enableCamera : params.enableCamera});
15					BX.addCustomEvent(this.editor, "onApply", BX.delegate(this.addFile, this));
16					BX.bind(BX("mfi-" + params.controlId + "-editor"), "click", BX.delegate(this.editor.click, this.editor));
17				}
18				this.init(params);
19				repo[params.controlId] = this;
20				this.template = BX.message('MFI_THUMB2').replace("#input_name#", this.params.inputName);
21				window["FILE_INPUT_" + params.controlId] = this; // for compatibility. Do not use
22				this.INPUT = BX("file_input_" + params['controlId']); // for compatibility. Do not use
23			}
24			catch (e) {
25				BX.debug(e);
26			}
27		};
28		d.prototype = {
29			init : function(params) {
30				this.agent = BX.Uploader.getInstance({
31					id : params['controlId'],
32					CID : params['controlUid'],
33					streams : 1,
34					uploadFormData : "N",
35					uploadMethod : "immediate",
36					uploadFileUrl : params["urlUpload"], //'/bitrix/tools/upload.php?lang=' + BX.message("LANGUAGE_ID"),
37					allowUpload : params["allowUpload"],
38					allowUploadExt : params["allowUploadExt"],
39					uploadMaxFilesize : params["uploadMaxFilesize"],
40					showImage : false,
41					sortItems : false,
42					input : BX("file_input_" + params['controlId']),
43					dropZone : this.controller.parentNode,
44					placeHolder : this.controller,
45					fields : {
46						thumb : {
47							tagName : "",
48							template : BX.message("MFI_THUMB")
49						}
50					}
51				});
52
53				this.fileEvents = {
54					onFileIsAttached : BX.delegate(this.onFileIsAttached, this),
55					onFileIsAppended : BX.delegate(this.onFileIsAppended, this),
56					onFileIsBound : BX.delegate(this.onFileIsBound, this),
57					onFileIsReadyToFrame : BX.delegate(this.onFileIsReadyToFrame, this),
58
59					onUploadStart : BX.delegate(this.onUploadStart, this),
60					onUploadProgress : BX.delegate(this.onUploadProgress, this),
61					onUploadDone : BX.delegate(this.onUploadDone, this),
62					onUploadError : BX.delegate(this.onUploadError, this),
63					onUploadRestore : BX.delegate(this.onUploadRestore, this)
64				};
65
66				BX.addCustomEvent(this.agent, "onAttachFiles", BX.delegate(this.onAttachFiles, this));
67				BX.addCustomEvent(this.agent, "onQueueIsChanged", BX.delegate(this.onQueueIsChanged, this));
68				BX.addCustomEvent(this.agent, "onFileIsInited", BX.delegate(this.onFileIsInited, this));
69				BX.addCustomEvent(this.agent, "onPackageIsInitialized", BX.delegate(function(pack) {
70					var t = {
71						mfi_mode : "upload",
72						cid : this.agent.CID,
73						moduleId : this.params["moduleId"],
74						forceMd5 : this.params["forceMd5"],
75						allowUpload : this.agent.limits["allowUpload"],
76						allowUploadExt : this.agent.limits["allowUploadExt"],
77						uploadMaxFilesize : this.agent.limits["uploadMaxFilesize"],
78						mfi_sign : this.params["controlSign"]
79					}, i;
80					for (i in t)
81					{
82						if (t.hasOwnProperty(i) && t[i])
83						{
84							pack.post.data[i] = t[i];
85							pack.post.size += ((i + "").length + (t[i] + "").length)
86						}
87					}
88				}, this));
89
90				var ar1 = [], ar2 = [], name, id,
91					values = BX.findChildren(this.controller, {tagName : "LI"});
92				for (var ii = 0; ii < values.length; ii++)
93				{
94					name = BX.findChild(values[ii], {attribute : {"data-bx-role" : "file-name"}}, true);
95					id = BX.findChild(values[ii], {attribute : {"data-bx-role" : "file-id"}}, true);
96					if (name && id)
97					{
98						ar1.push({ name : name.innerHTML,  file_id : id.value});
99						ar2.push(values[ii]);
100					}
101				}
102				this.agent.onAttach(ar1, ar2);
103				this.inited = true;
104				this.checkUploadControl();
105			},
106			checkUploadControl : function() {
107				if (BX(this.button))
108				{
109					if (!(this.params["maxCount"] > 0 && this.params["maxCount"] <= this.agent.getItems().length))
110					{
111						this.button.removeAttribute("disable");
112					}
113					else if (this.params["maxCount"] == 1)
114					{
115						// TODO smth
116					}
117					else //  && this.params["maxCount"] >= this.agent.getItems().length
118					{
119						this.button.setAttribute("disable", "Y");
120					}
121				}
122			},
123			onQueueIsChanged : function() {
124				if (this.params['maxCount'] > 0)
125				{
126					this.checkUploadControl();
127				}
128			},
129			onAttachFiles : function(files) {
130				var error = false, n;
131				if (files && this.inited === true && this.params['maxCount'] > 0)
132				{
133					if (this.params['maxCount'] == 1 && files.length > 0)
134					{
135						while (this.agent.getItems().length > 0)
136						{
137							this.deleteFile(this.agent.getItems().getFirst(), false);
138						}
139
140						while (files.length > 1)
141							files.pop();
142					}
143					var acceptableL = this.params['maxCount'] - this.agent.getItems().length;
144					acceptableL = (acceptableL > 0 ? acceptableL : 0);
145					while (files.length > acceptableL)
146					{
147						files.pop();
148						error = true;
149					}
150				}
151				if (error)
152				{
153					this.onError("Too much files.");
154				}
155				BX.onCustomEvent(this, 'onFileUploaderChange', [files, this]);
156				return files;
157			},
158			onFileIsInited : function(id, file) {
159				for (var ii in this['fileEvents'])
160				{
161					if (this['fileEvents'].hasOwnProperty(ii))
162						BX.addCustomEvent(file, ii, this['fileEvents'][ii]);
163				}
164			},
165			onFileIsAppended : function(id, item) {
166				// append canvas
167				var node = this.agent.getItem(id);
168				this.bindEventsHandlers(node.node, item);
169			},
170			onFileIsBound : function(id, item) {
171				var node = this.agent.getItem(id);
172				this.bindEventsHandlers(node.node, item);
173			},
174			bindEventsHandlers : function(node, item) {
175				var n = BX.findChild(node, {attribute : {"data-bx-role" : "file-delete"}}, true), n1;
176				if (n)
177					BX.bind(n, "click", BX.proxy(function(){
178						this.deleteFile(item);
179				}, this));
180
181				n = BX.findChild(node, {attribute : {"data-bx-role" : "file-preview"}}, true);
182				if (n)
183				{
184					n.removeAttribute("data-bx-role");
185					if (item.file.parentCanvas)
186					{
187						var
188							props = BX.UploaderUtils.scaleImage(item.file.parentCanvas, { width : 100, height : 100}, "exact"),
189							c = BX.create("CANVAS", {props : {width : 100, height : 100}});
190						n.appendChild(c);
191						c.getContext("2d").drawImage(item.file.parentCanvas, props.source.x, props.source.y, props.source.width, props.source.height, 0, 0, props.destin.width, props.destin.height);
192						item.canvas = c;
193					}
194				}
195				item.file.parentCanvas = null;
196				n = BX.findChild(node, {tagName : "A", attribute : {"data-bx-role" : "file-name"}}, true);
197				if (n)
198				{
199					if (this.editor && ((n1 = BX.findChild(node, {tagName : "CANVAS"}, true)) && n1 || (n1 = BX.findChild(node, {tagName : "IMG"}, true)) && n1))
200					{
201						BX.bind(n, "click", BX.proxy(function(e) {
202							BX.PreventDefault(e);
203							this.editor.showFile({name : n.innerHTML, tmp_url : n.href});
204							return false;}, this));
205					}
206					else if (n.getAttribute("href") === "#")
207					{
208						BX.bind(n, "click", BX.proxy(function(e) {
209							BX.PreventDefault(e);
210							return false;}, this));
211					}
212				}
213			},
214			addFile : function(file, canvas) {
215				file.name = (file["name"] || 'image.png');
216				file.parentCanvas = canvas;
217				this.agent.onAttach([file]);
218			},
219			deleteFile : function(item) {
220				var pointer = (item ? this.agent.getItem(item.id) : false);
221				if (!pointer)
222					return;
223				item = pointer.item;
224
225				var node = pointer.node;
226				var newInput;
227				if (item.file["justUploaded"] === true && item.file["file_id"] > 0)
228				{
229					var data = {
230						fileID : item.file["file_id"],
231						sessid : BX.bitrix_sessid(),
232						cid : this.agent.CID,
233						mfi_mode : "delete"
234					};
235					BX.ajax.post(this.agent.uploadFileUrl, data);
236				}
237				else
238				{
239					var parentNode = node.parentNode.parentNode,
240						n = BX.findChild(node, {tagName : "INPUT", attribute : { "data-bx-role" : "file-id"} }, true );
241					if (n)
242					{
243						var name = n.name,
244							v = n.value,
245							nDelNameCompat = name + '_del',
246							nDelName = this.agent.id + '_deleted[]';
247
248						if (name.indexOf('[') > 0)
249						{
250							nDelNameCompat = name.substr(0, name.indexOf('[')) + '_del' + name.substr(name.indexOf('['));
251						}
252
253						newInput = BX.create("INPUT", { props : {
254							name : name,
255							type : "hidden",
256							value : v}});
257						parentNode.appendChild(newInput);
258						var node1 = BX.create("INPUT", { props : {
259							name : nDelNameCompat,
260							type : "hidden",
261							value : v}});
262						parentNode.appendChild(node1);
263						node1 = BX.create("INPUT", { props : {
264							name : nDelName,
265							type : "hidden",
266							value : v}});
267						parentNode.appendChild(node1);
268					}
269				}
270
271				for (var ii in this['fileEvents'])
272				{
273					if (this['fileEvents'].hasOwnProperty(ii))
274						BX.addCustomEvent(item, ii, this['fileEvents'][ii]);
275				}
276
277				BX.unbindAll(node);
278				var fileId = (item.file ? item.file["file_id"] : null);
279				delete item.hash;
280				item.deleteFile('deleteFile');
281				if (fileId)
282				{
283					BX.onCustomEvent(this, 'onDeleteFile', [fileId, item, this]);  // for compatibility
284					BX.onCustomEvent(this, 'onFileUploaderChange', [[fileId], this]);  // for compatibility. Do not use
285					if(!!newInput)
286					{
287						BX.fireEvent(newInput, 'change');
288					}
289				}
290			},
291			_deleteFile : function() { // for compatibility. Do not Use
292
293			},
294			clear : function() {
295				while (this.agent.getItems().length > 0)
296				{
297					this.deleteFile(this.agent.getItems().getFirst(), false);
298				}
299			},
300			onUploadStart : function(item) {
301				var node = this.agent.getItem(item.id).node;
302				if (node)
303					BX.addClass(node, "uploading");
304			},
305			onUploadProgress : function(item, progress) {
306				progress = Math.min(progress, 98);
307				var id = item.id;
308				if (!item.__progressBarWidth)
309					item.__progressBarWidth = 5;
310				if (progress > item.__progressBarWidth)
311				{
312					item.__progressBarWidth = Math.ceil(progress);
313					item.__progressBarWidth = (item.__progressBarWidth > 100 ? 100 : item.__progressBarWidth);
314					if (BX('wdu' + id + 'Progressbar'))
315						BX.adjust(BX('wdu' + id + 'Progressbar'), { style : { width : item.__progressBarWidth + '%' } } );
316					if (BX('wdu' + id + 'ProgressbarText'))
317						BX.adjust(BX('wdu' + id + 'ProgressbarText'), { text : item.__progressBarWidth + '%' } );
318				}
319			},
320			onUploadDone : function(item, result) {
321				var node = this.agent.getItem(item.id).node,
322					file = result["file"];
323				if (BX(node))
324				{
325					BX.removeClass(node, "uploading");
326					BX.addClass(node, "saved");
327
328					var html = this.template, value;
329					file["ext"] = item.ext;
330					file["preview_url"] = (item.canvas ? item.canvas.toDataURL("image/png") : "/bitrix/images/1.gif");
331					item.canvas = null;
332					delete item.canvas;
333					for (var ii in file)
334					{
335						if (file.hasOwnProperty(ii))
336						{
337							value = file[ii];
338							if (ii.toLowerCase() === 'size')
339								value = BX.UploaderUtils.getFormattedSize(value, 0);
340							else if (ii.toLowerCase() === 'name')
341								value = file["originalName"];
342							html = html.replace(new RegExp("#" + ii.toLowerCase() + "#", "gi"), BX.util.htmlspecialchars(value)).replace(new RegExp("#" + ii.toUpperCase() + "#", "gi"), BX.util.htmlspecialchars(value));
343						}
344					}
345					item.file.file_id = file["file_id"];
346					item.file.justUploaded = true;
347					item.name = file["originalName"];
348					node.innerHTML = html;
349					this.bindEventsHandlers(node, item);
350					if (this.params.inputName.indexOf('[') < 0)
351					{
352						BX.remove(BX.findChild(node.parentNode.parentNode, {tagName : "INPUT", attr : {name : (this.params.inputName)}}, false));
353						BX.remove(BX.findChild(node.parentNode.parentNode, {tagName : "INPUT", attr : {name : (this.params.inputName + '_del')}}, false));
354					}
355					BX.onCustomEvent(this, 'onAddFile', [file["file_id"], this, file, node]); // for compatibility
356					BX.onCustomEvent(this, 'onUploadDone', [result["file"], item, this]);
357					BX.fireEvent(BX('file-' + file["file_id"]), 'change');
358				}
359				else
360				{
361					this.onUploadError(item, result, this.agent);
362				}
363			},
364			onUploadError : function(item, params, specify) {
365				// TODO show Error
366				var node = this.agent.getItem(item.id).node,
367					error = BX.message("MFI_UPLOADING_ERROR");
368				if (params && params.error)
369					error = params.error;
370				BX.removeClass(node, "uploading");
371				BX.addClass(node, "error");
372				node.appendChild(BX.create('DIV', {attrs : { className : "upload-file-error" }, html : error}));
373				BX.onCustomEvent(this, 'onErrorFile', [item["file"], this]); // for compatibility
374			},
375			onError : function(stream, pIndex, data) {
376				var defaultErrorText = 'Uploading error.',
377					errorText = defaultErrorText, item, id;
378				if (data)
379				{
380					if (data["error"] && typeof data["error"] == "string")
381						errorText = data["error"];
382					else if (data["message"] && typeof data["message"] == "string")
383						errorText = data["message"];
384					else if (BX.type.isArray(data["errors"]) && data["errors"].length > 0)
385					{
386						errorText = [];
387						for (var ii = 0; ii < data["errors"].length; ii++)
388						{
389							if (typeof data["errors"][ii] == "object" && data["errors"][ii]["message"])
390								errorText.push(data["errors"][ii]["message"]);
391						}
392						if (errorText.length <= 0)
393							errorText.push('Uploading error.');
394						errorText = errorText.join(' ');
395					}
396				}
397				stream.files = (stream.files || {});
398				for (id in stream.files)
399				{
400					if (stream.files.hasOwnProperty(id))
401					{
402						item = this.agent.queue.items.getItem(id);
403						this.onUploadError(item, {error : errorText}, (errorText != defaultErrorText));
404					}
405				}
406			}
407		};
408		return d;
409	})();
410
411	BX.MFInput = {
412		init : function(params) {
413			return new uploader(params);
414		},
415		get : function(controlId) {
416			return (repo[controlId] || null);
417		}
418	}
419})();

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.