PageSourceSearch

https://www.gigi.ru/bitrix/js/main/core/core_uploader/queue.js?169887979518127

js gigi.ru collected 2026-10-04 00:13:31 UTC 18,127 bytes, 591 lines download raw bytes

1;(function(window){
2	window.BX = window['BX'] || {};
3	if (window.BX["UploaderQueue"])
4		return false;
5	var
6		BX = window.BX,
7		statuses = { "new" : 0, ready : 1, preparing : 2, inprogress : 3, done : 4, failed : 5, stopped : 6, changed : 7, uploaded : 8};
8	/**
9	 * @return {BX.UploaderQueue}
10	 * @params array
11	 * @params[placeHolder] - DOM node to append files /OL or UL/
12	 */
13	BX.UploaderQueue = function (params, limits, caller)
14	{
15		this.dialogName = "BX.UploaderQueue";
16		limits = (!!limits ? limits : {});
17
18		this.limits = {
19			phpPostMaxSize : limits["phpPostMaxSize"],
20			phpUploadMaxFilesize : limits["phpUploadMaxFilesize"],
21			uploadMaxFilesize : (limits["uploadMaxFilesize"] > 0 ? limits["uploadMaxFilesize"] : 0),
22			uploadFileWidth : (limits["uploadFileWidth"] > 0 ? limits["uploadFileWidth"] : 0),
23			uploadFileHeight : (limits["uploadFileHeight"] > 0 ? limits["uploadFileHeight"] : 0)};
24
25		this.placeHolder = BX(params["placeHolder"]);
26		this.showImage = (params["showImage"] !== false && params["showImage"] !== 'N');
27		this.sortItems = (params["sortItems"] !== false && params["sortItems"] !== 'N');
28		this.fileCopies = params["copies"];
29		this.fileFields = params["fields"];
30
31		this.uploader = caller;
32		this.itForUpload = new BX.UploaderUtils.Hash();
33		this.items = new BX.UploaderUtils.Hash();
34		this.itUploaded = new BX.UploaderUtils.Hash();
35		this.itFailed = new BX.UploaderUtils.Hash();
36		this.thumb = { tagName : "LI", className : "bx-bxu-thumb-thumb"};
37		if (!!params["thumb"])
38		{
39			for (var ii in params["thumb"])
40			{
41				if (params["thumb"].hasOwnProperty(ii) && this.thumb.hasOwnProperty(ii))
42				{
43					this.thumb[ii] = params["thumb"][ii];
44				}
45			}
46		}
47
48		BX.addCustomEvent(caller, "onItemIsAdded", BX.delegate(this.addItem, this));
49		BX.addCustomEvent(caller, "onFileIsDeleted", BX.delegate(this.deleteItem, this));
50		BX.addCustomEvent(caller, "onFileIsReinited", BX.delegate(this.reinitItem, this));
51
52		this.log('Initialized');
53		return this;
54	};
55	BX.UploaderQueue.prototype = {
56		showError : function(text) { this.log('Error! ' + text); },
57		log : function(text)
58		{
59			BX.UploaderUtils.log('queue', text);
60		},
61		addItem : function (file, being)
62		{
63			var isImage;
64			if (!this.showImage)
65				isImage = false;
66			else if (BX.type.isDomNode(file))
67				isImage = BX.UploaderUtils.isImage(file.value, null, null);
68			else
69				isImage = BX.UploaderUtils.isImage(file["name"], file["type"], file["size"]);
70
71			BX.onCustomEvent(this.uploader, "onFileIsBeforeCreated", [file, being, isImage, this.uploader]);
72
73			var params = {copies : this.fileCopies, fields : this.fileFields},
74				res = (isImage ?
75					new BX.UploaderImage(file, params, this.limits, this.uploader) :
76					new BX.UploaderFile(file, params, this.limits, this.uploader)),
77					children, node,
78					itemStatus = {status : statuses.ready};
79
80			BX.onCustomEvent(res, "onFileIsAfterCreated", [res, being, itemStatus, this.uploader]);
81			BX.onCustomEvent(this.uploader, "onFileIsAfterCreated", [res, being, itemStatus, this.uploader]);
82
83			this.items.setItem(res.id, res);
84			if (being || itemStatus["status"] !== statuses.ready)
85			{
86				this.itUploaded.setItem(res.id, res);
87			}
88			else
89			{
90				this.itForUpload.setItem(res.id, res);
91			}
92			if (!!this.placeHolder)
93			{
94				if (BX(being))
95				{
96					res.thumbNode = node = BX(being);
97					node.setAttribute("bx-bxu-item-id", res.id);
98				}
99				else
100				{
101					children = res.makeThumb();
102					node = BX.create(this.thumb.tagName, {
103						attrs : {
104							id : res.id + 'Item',
105							'bx-bxu-item-id' : res.id,
106							className : this.thumb.className}
107					});
108					if (BX.type.isNotEmptyString(children))
109					{
110						if (this.thumb.tagName == 'TR')
111						{
112							children = children.replace(/[\n\t]/gi, "").replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1");
113							if (!!children["trim"])
114								children = children.trim();
115							var replaceFunction = function(str, tdParams, tdInnerHTML)
116							{
117								var td = node.insertCell(-1),
118									attrs = {
119										colspan : true,
120										headers : true,
121										accesskey : true,
122										"class" : true,
123										contenteditable : true,
124										contextmenu : true,
125										dir : true,
126										hidden : true,
127										id : true,
128										lang : true,
129										spellcheck : true,
130										style : true,
131										tabindex : true,
132										title : true,
133										translate : true
134									}, param;
135								td.innerHTML = tdInnerHTML;
136								tdParams = tdParams.split(" ");
137								while ((param = tdParams.pop()) && param)
138								{
139									param = param.split("=");
140									if (param.length == 2)
141									{
142										param[0] = param[0].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1");
143										param[1] = param[1].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1");
144										if (attrs[param[0]] === true)
145											td.setAttribute(param[0], param[1]);
146										else
147											td[param[0]] = param[1];
148									}
149								}
150								return "";
151							}, regex = /^<td(.*?)>(.*?)<\/td>/i;
152							window.data1 = children;
153							while (regex.test(children))
154								children = children.replace(regex, replaceFunction);
155						}
156						else
157						{
158							node.innerHTML = children;
159						}
160					}
161					else if (BX.type.isDomNode(children))
162					{
163						BX.adjust(node, { children : [children] } );
164					}
165				}
166
167				if (!!window["jsDD"] && this.sortItems)
168				{
169					if (!this._onbxdragstart)
170					{
171						this._onbxdragstart = BX.delegate(this.onbxdragstart, this);
172						this._onbxdragstop = BX.delegate(this.onbxdragstop, this);
173						this._onbxdrag = BX.delegate(this.onbxdrag, this);
174						this._onbxdraghout = BX.delegate(this.onbxdraghout, this);
175						this._onbxdestdraghover = BX.delegate(this.onbxdestdraghover, this);
176						this._onbxdestdraghout = BX.delegate(this.onbxdestdraghout, this);
177						this._onbxdestdragfinish = BX.delegate(this.onbxdestdragfinish, this);
178					}
179					BX.addClass(node, "bx-drag-draggable");
180					node.onbxdragstart = this._onbxdragstart;
181					node.onbxdragstop = this._onbxdragstop;
182					node.onbxdrag = this._onbxdrag;
183					node.onbxdraghout = this._onbxdraghout;
184					window.jsDD.registerObject(node);
185
186					node.onbxdestdraghover = this._onbxdestdraghover;
187					node.onbxdestdraghout = this._onbxdestdraghout;
188					node.onbxdestdragfinish = this._onbxdestdragfinish;
189					window.jsDD.registerDest(node);
190					var inputs = BX.findChild(node, {tagName : "INPUT", props : {"type" : "text"}}, true, true);
191					for (var ii = 0; ii <= inputs.length; ii++)
192					{
193						BX.bind(inputs[ii], "mousedown", BX.eventCancelBubble);
194					}
195				}
196				node.setAttribute("bx-item-id", res.id);
197				if (BX(being))
198				{
199					BX.onCustomEvent(this.uploader, "onFileIsBound", [res.id, res, this.caller, being]);
200					BX.onCustomEvent(res, "onFileIsBound", [res.id, res, this.caller, being]);
201				}
202				else if (!!being)
203				{
204					this.placeHolder.appendChild(node);
205					BX.onCustomEvent(this.uploader, "onFileIsAttached", [res.id, res, this.caller, being]);
206					BX.onCustomEvent(res, "onFileIsAttached", [res.id, res, this.caller, being]);
207				}
208				else
209				{
210					this.placeHolder.appendChild(node);
211					BX.onCustomEvent(this.uploader, "onFileIsAppended", [res.id, res, this.caller]);
212					BX.onCustomEvent(res, "onFileIsAppended", [res.id, res, this.caller]);
213				}
214			}
215			BX.onCustomEvent(this.uploader, "onQueueIsChanged", [this, "add", res.id, res]);
216		},
217		getItem : function(id)
218		{
219			var item = this.items.getItem(id);
220			if (item)
221				return {item : item, node : (item.thumbNode || BX(id + 'Item'))};
222			return null;
223		},
224		onbxdragstart : function() {
225			var item = BX.proxy_context,
226				id = (item && item.getAttribute("bx-item-id"));
227			if (id)
228			{
229				var template = item.innerHTML.replace(new RegExp(id, "gi"), "DragCopy");
230				item.__dragCopyDiv = BX.create('DIV', {
231					attrs : {
232						className : "bx-drag-object " + item.className
233					},
234					style : {
235						position : "absolute",
236						zIndex : 10,
237						width : item.clientWidth + 'px'
238					},
239					html : template
240				});
241				item.__dragCopyPos = BX.pos(item);
242				BX.onCustomEvent(this.uploader, "onBxDragStart", [item, item.__dragCopyDiv]);
243				document.body.appendChild(item.__dragCopyDiv);
244
245				BX.addClass(item, "bx-drag-source");
246				var c = BX('DragCopyProperCanvas'),
247					c1,
248					it = this.items.getItem(id);
249				if (c && (it && BX(it.canvas)))
250				{
251					c1 = it.canvas.cloneNode(true);
252					c.parentNode.replaceChild(c1, c);
253					c1.getContext("2d").drawImage(it.canvas, 0, 0);
254				}
255			}
256			return true;
257		},
258		onbxdragstop : function() {
259			var item = BX.proxy_context;
260			if (item.__dragCopyDiv)
261			{
262				BX.removeClass(item, "bx-drag-source");
263				item.__dragCopyDiv.parentNode.removeChild(item.__dragCopyDiv);
264				item.__dragCopyDiv = null;
265				delete item['__dragCopyDiv'];
266				delete item['__dragCopyPos'];
267			}
268			return true;
269		},
270		onbxdrag : function(x, y) {
271			var item = BX.proxy_context,
272				div = item.__dragCopyDiv;
273			if (div)
274			{
275				if (item.__dragCopyPos)
276				{
277					if (!item.__dragCopyPos.deltaX)
278						item.__dragCopyPos.deltaX = item.__dragCopyPos.left - x;
279					if (!item.__dragCopyPos.deltaY)
280						item.__dragCopyPos.deltaY = item.__dragCopyPos.top - y;
281					x += item.__dragCopyPos.deltaX;
282					y += item.__dragCopyPos.deltaY;
283				}
284
285				div.style.left = x + 'px';
286				div.style.top = y + 'px';
287			}
288		},
289		onbxdraghout : function(currentNode, x, y) {
290		},
291		onbxdestdraghover : function(currentNode) {
292			if (!currentNode || !currentNode.hasAttribute("bx-bxu-item-id") || !this.items.hasItem(currentNode.getAttribute("bx-bxu-item-id")))
293				return;
294			var item = BX.proxy_context;
295			BX.addClass(item, "bx-drag-over");
296			return true;
297		},
298		onbxdestdraghout : function() {
299			var item = BX.proxy_context;
300			BX.removeClass(item, "bx-drag-over");
301			return true;
302		},
303		onbxdestdragfinish : function(currentNode) {
304			var item = BX.proxy_context;
305			BX.removeClass(item, "bx-drag-over");
306			if(item == currentNode || !BX.hasClass(currentNode, "bx-drag-draggable"))
307				return true;
308			var id = currentNode.getAttribute("bx-bxu-item-id");
309			if (!this.items.hasItem(id))
310				return;
311
312			var obj = item.parentNode,
313				n = obj.childNodes.length,
314				act, it, buff, j;
315
316			for (j=0; j<n; j++)
317			{
318				if (obj.childNodes[j] == item)
319					item.number = j;
320				else if (obj.childNodes[j] == currentNode)
321					currentNode.number = j;
322
323				if (currentNode.number > 0 && item.number > 0)
324					break;
325			}
326
327			if (this.itForUpload.hasItem(id))
328			{
329				act = (item.number <= currentNode.number ? "beforeItem" : (
330					item.nextSibling ? "afterItem" : "inTheEnd"));
331				it = null;
332				if (act != "inTheEnd")
333				{
334					for (j = item.number + (act == "beforeItem" ? 0 : 1); j < n; j++)
335					{
336						if (this.itForUpload.hasItem(obj.childNodes[j].getAttribute("bx-bxu-item-id")))
337						{
338							it = obj.childNodes[j].getAttribute("bx-bxu-item-id");
339							break;
340						}
341					}
342					if (it === null)
343						act = "inTheEnd";
344				}
345				buff = this.itForUpload.removeItem(currentNode.getAttribute("bx-bxu-item-id"));
346				if (act != "inTheEnd")
347					this.itForUpload.insertBeforeItem(buff.id, buff, it);
348				else
349					this.itForUpload.setItem(buff.id, buff);
350			}
351
352			act = (item.number <= currentNode.number ? "beforeItem" : (
353				item.nextSibling ? "afterItem" : "inTheEnd"));
354			it = null;
355			if (act != "inTheEnd")
356			{
357				for (j = item.number + (act == "beforeItem" ? 0 : 1); j < n; j++)
358				{
359					if (this.items.hasItem(obj.childNodes[j].getAttribute("bx-bxu-item-id")))
360					{
361						it = obj.childNodes[j].getAttribute("bx-bxu-item-id");
362						break;
363					}
364				}
365				if (it === null)
366					act = "inTheEnd";
367			}
368			buff = this.items.removeItem(currentNode.getAttribute("bx-bxu-item-id"));
369			if (act != "inTheEnd")
370				this.items.insertBeforeItem(buff.id, buff, it);
371			else
372				this.items.setItem(buff.id, buff);
373
374			currentNode.parentNode.removeChild(currentNode);
375			if (item.number <= currentNode.number)
376			{
377				item.parentNode.insertBefore(currentNode, item);
378			}
379			else if (item.nextSibling)
380			{
381				item.parentNode.insertBefore(currentNode, item.nextSibling);
382			}
383			else
384			{
385				for (j=0; j<n; j++)
386				{
387					if (obj.childNodes[j] == item)
388						item.number = j;
389					else if (obj.childNodes[j] == currentNode)
390						currentNode.number = j;
391				}
392				if (item.number <= currentNode.number)
393				{
394					item.parentNode.insertBefore(currentNode, item);
395				}
396				else
397				{
398					item.parentNode.appendChild(currentNode);
399				}
400			}
401			BX.onCustomEvent(item, "onFileOrderIsChanged", [item.id, item, this.caller]);
402			BX.onCustomEvent(this.uploader, "onQueueIsChanged", [this, "sort", item.id, item]);
403			return true;
404		},
405		deleteItem : function (id, item) {
406			var pointer = this.getItem(id), node;
407			if (pointer && (!this.placeHolder || ((node = pointer.node) && node)))
408			{
409				if (!!node)
410				{
411					if (!!window["jsDD"])
412					{
413						node.onmousedown = null;
414						node.onbxdragstart = null;
415						node.onbxdragstop = null;
416						node.onbxdrag = null;
417						node.onbxdraghout = null;
418						node.onbxdestdraghover = null;
419						node.onbxdestdraghout = null;
420						node.onbxdestdragfinish = null;
421						node.__bxpos = null;
422
423						window.jsDD.arObjects[node.__bxddid] = null;
424						delete window.jsDD.arObjects[node.__bxddid];
425
426						window.jsDD.arDestinations[node.__bxddeid] = null;
427						delete window.jsDD.arDestinations[node.__bxddeid];
428					}
429					BX.unbindAll(node);
430					if (item["replaced"] !== true)
431						node.parentNode.removeChild(node);
432				}
433
434				this.items.removeItem(id);
435				this.itUploaded.removeItem(id);
436				this.itFailed.removeItem(id);
437				this.itForUpload.removeItem(id);
438				BX.onCustomEvent(this.uploader, "onQueueIsChanged", [this, "delete", id, item]);
439				return true;
440			}
441			return false;
442		},
443		reinitItem : function (id, item) {
444			var node, children;
445			if (!!this.placeHolder && this.items.hasItem(id) && (node = BX(id + 'Item')) && node)
446			{
447				children = item.makeThumb();
448				if (BX.type.isNotEmptyString(children))
449				{
450					if (this.thumb.tagName == 'TR')
451					{
452						children = children.replace(/[\n\t]/gi, "").replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1");
453						if (!!children["trim"])
454							children = children.trim();
455						var replaceFunction = function(str, tdParams, tdInnerHTML)
456						{
457							var td = node.insertCell(-1),
458								attrs = {
459									colspan : true,
460									headers : true,
461									accesskey : true,
462									"class" : true,
463									contenteditable : true,
464									contextmenu : true,
465									dir : true,
466									hidden : true,
467									id : true,
468									lang : true,
469									spellcheck : true,
470									style : true,
471									tabindex : true,
472									title : true,
473									translate : true
474								}, param;
475							td.innerHTML = tdInnerHTML;
476							tdParams = tdParams.split(" ");
477							while ((param = tdParams.pop()) && param)
478							{
479								param = param.split("=");
480								if (param.length == 2)
481								{
482									param[0] = param[0].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1");
483									param[1] = param[1].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1");
484									if (attrs[param[0]] === true)
485										td.setAttribute(param[0], param[1]);
486									else
487										td[param[0]] = param[1];
488								}
489							}
490							return "";
491						}, regex = /^<td(.*?)>(.*?)<\/td>/i;
492						window.data1 = children;
493						while (regex.test(children))
494							children = children.replace(regex, replaceFunction);
495					}
496					else
497					{
498						node.innerHTML = children;
499					}
500				}
501				else if (BX.type.isDomNode(children))
502				{
503					while (BX(node.firstChild))
504					{
505						BX.remove(node.firstChild);
506					}
507					BX.adjust(node, { children : [children] } );
508				}
509				BX.onCustomEvent(this.uploader, "onFileIsAppended", [item.id, item, this.caller]);
510				BX.onCustomEvent(item, "onFileIsAppended", [item.id, item, this.caller]);
511			}
512		},
513		clear : function()
514		{
515			var item;
516			while ((item = this.items.getFirst()) && !!item)
517				this.deleteItem(item.id, item);
518		},
519		restoreFiles : function(data, restoreErrored, startAgain)
520		{
521			data.reset();
522			var item, copy, erroredFile;
523			while((item = data.getNext()) && item)
524			{
525				erroredFile = this.itFailed.hasItem(item.id);
526				if (restoreErrored === true)
527				{
528					this.itFailed.removeItem(item.id);
529				}
530
531				if (!this.items.hasItem(item.id) || this.itFailed.hasItem(item.id))
532				{
533					continue;
534				}
535
536				if (startAgain === true || startAgain !== false && erroredFile) // for compatibility
537				{
538					delete item["uploadStatus"];
539
540					delete item.file["uploadStatus"];
541					delete item.file["firstChunk"];
542					delete item.file["package"];
543					delete item.file["packages"];
544
545					if (item.file["copies"])
546					{
547						item.file["copies"].reset();
548						while((copy = item.file["copies"].getNext()) && copy)
549						{
550							delete copy["uploadStatus"];
551							delete copy["firstChunk"];
552							delete copy["package"];
553							delete copy["packages"];
554						}
555						item.file["copies"].reset();
556					}
557					item["restored"] = (startAgain === true ? "Y" : "C"); // Start again or continue
558				}
559				else
560				{
561					if (erroredFile) // If a error was occurred on the last step we should send this piece again
562					{
563						if (item.file["package"])
564						{
565							item.file["package"]--;
566						}
567						if (item.file["copies"])
568						{
569							item.file["copies"].reset();
570
571							while((copy = item.file["copies"].getNext()) && copy)
572							{
573								delete copy["uploadStatus"];
574								delete copy["firstChunk"];
575								delete copy["package"];
576								delete copy["packages"];
577							}
578							item.file["copies"].reset();
579						}
580					}
581
582					item["restored"] = "C"; // Continue
583				}
584				this.itUploaded.removeItem(item.id);
585				this.itForUpload.setItem(item.id, item);
586				BX.onCustomEvent(item, "onUploadRestore", [item]);
587			}
588		}
589	};
590	return statuses;
591}(window));

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.