1; /* /bitrix/js/main/core/core_uploader/common.js?178694347215477*/ 2; /* /bitrix/js/main/core/core_uploader/uploader.js?1786943472100786*/ 3; /* /bitrix/js/main/core/core_uploader/file.js?178694347238495*/ 4; /* /bitrix/js/main/core/core_uploader/queue.js?178694347218127*/ 5 6; /* Start:"a:4:{s:4:"full";s:60:"/bitrix/js/main/core/core_uploader/common.js?178694347215477";s:6:"source";s:44:"/bitrix/js/main/core/core_uploader/common.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/ 7;(function(window){ 8 window.BX = window['BX'] || {}; 9 if (window.BX["UploaderUtils"]) 10 return false; 11 var BX = window.BX; 12 BX.UploaderLog = []; 13 BX.UploaderDebug = false; 14 var statuses = { "new" : 0, ready : 1, preparing : 2, inprogress : 3, done : 4, failed : 5, stopped : 6, changed : 7, uploaded : 8}; 15 BX.UploaderUtils = { 16 statuses : statuses, 17 getId : function() { return (new Date().valueOf() + Math.round(Math.random() * 1000000)); }, 18 log : function(){ 19 if (BX.UploaderDebug === true) 20 { 21 console.log(arguments); 22 } 23 else 24 { 25 BX.UploaderLog.push(arguments); 26 } 27 }, 28 Hash : (function(){ 29 var d = function() { 30 this.length = 0; 31 this.items = {}; 32 this.order = []; 33 var i; 34 if (arguments.length == 1 && BX.type.isArray(arguments[0]) && arguments[0].length > 0) 35 { 36 var data = arguments[0]; 37 for (i = 0; i < data.length; i++) 38 { 39 if (data[i] && typeof data[i] == "object" && data[i]["id"]) 40 { 41 this.setItem(data[i]["id"], data[i]); 42 } 43 } 44 } 45 else 46 { 47 for (i = 0; i < arguments.length; i += 2) 48 this.setItem(arguments[i], arguments[i + 1]); 49 } 50 }; 51 d.prototype = { 52 getIds : function() 53 { 54 return this.order; 55 }, 56 getQueue : function(id) 57 { 58 id += ''; 59 return BX.util.array_search(id, this.order); 60 }, 61 getByOrder : function(order) 62 { 63 return this.getItem(this.order[order]); 64 }, 65 removeItem : function(in_key) 66 { 67 in_key += ''; 68 var tmp_value, number; 69 if (typeof(this.items[in_key]) != 'undefined') { 70 tmp_value = this.items[in_key]; 71 number = this.getQueue(in_key); 72 this.pointer -= (this.pointer >= number ? 1 : 0); 73 delete this.items[in_key]; 74 this.order = BX.util.deleteFromArray(this.order, number); 75 this.length = this.order.length; 76 77 } 78 return tmp_value; 79 }, 80 81 getItem : function(in_key) { 82 in_key += ''; 83 return this.items[in_key]; 84 }, 85 86 unshiftItem : function(in_key, in_value) 87 { 88 in_key += ''; 89 if (typeof(in_value) != 'undefined') 90 { 91 if (typeof(this.items[in_key]) == 'undefined') 92 { 93 this.order.unshift(in_key); 94 this.length = this.order.length; 95 } 96 this.items[in_key] = in_value; 97 } 98 return in_value; 99 }, 100 setItem : function(in_key, in_value) 101 { 102 in_key += ''; 103 if (typeof(in_value) != 'undefined') 104 { 105 if (typeof(this.items[in_key]) == 'undefined') 106 { 107 this.order.push(in_key); 108 this.length = this.order.length; 109 } 110 this.items[in_key] = in_value; 111 } 112 return in_value; 113 }, 114 115 hasItem : function(in_key) 116 { 117 in_key += ''; 118 return typeof(this.items[in_key]) != 'undefined'; 119 }, 120 insertBeforeItem : function(in_key, in_value, after_key) 121 { 122 in_key += ''; 123 if (typeof(in_value) != 'undefined') 124 { 125 if (typeof(this.items[in_key]) == 'undefined') 126 { 127 this.order.splice(this.getQueue(after_key), 0, in_key); 128 this.length = this.order.length; 129 } 130 this.items[in_key] = in_value; 131 } 132 return in_value; 133 }, 134 getFirst : function() 135 { 136 var in_key, item = null; 137 for (var ii = 0; ii < this.order.length; ii++) 138 { 139 in_key = this.order[ii]; 140 if (!!in_key && this.hasItem(in_key)) 141 { 142 item = this.getItem(in_key); 143 break; 144 } 145 } 146 return item; 147 }, 148 getNext : function() 149 { 150 this.pointer = (0 <= this.pointer && this.pointer < this.order.length ? this.pointer : -1); 151 var res = this.getItem(this.order[this.pointer + 1]); 152 if (!!res) 153 this.pointer++; 154 else 155 this.pointer = -1; 156 return res; 157 }, 158 getPrev : function() 159 { 160 this.pointer = (0 <= this.pointer && this.pointer < this.order.length ? this.pointer : 0); 161 var res = this.getItem(this.order[this.pointer - 1]); 162 if (!!res) 163 this.pointer--; 164 return res; 165 }, 166 reset : function() 167 { 168 this.pointer = -1; 169 }, 170 setPointer : function(in_key) 171 { 172 this.pointer = this.getQueue(in_key); 173 return this.pointer; 174 }, 175 getLast : function() 176 { 177 var in_key, item = null; 178 for (var ii = this.order.length; ii >=0; ii--) 179 { 180 in_key = this.order[ii]; 181 if (!!in_key && this.hasItem(in_key)) 182 { 183 item = this.getItem(in_key); 184 break; 185 } 186 } 187 return item; 188 } 189 }; 190 return d; 191 })(), 192 getFileNameOnly : function (name) 193 { 194 var delimiter = "\\", start = name.lastIndexOf(delimiter), finish = name.length; 195 if (start == -1) 196 { 197 delimiter = "/"; 198 start = name.lastIndexOf(delimiter); 199 } 200 if ((start + 1) == name.length) 201 { 202 finish = start; 203 start = name.substring(0, finish).lastIndexOf(delimiter); 204 } 205 name = name.substring(start + 1, finish); 206 if (delimiter == "/" && name.indexOf("?") > 0) 207 { 208 name = name.substring(0, name.indexOf("?")); 209 } 210 211 if (name == '') 212 name = 'noname'; 213 return name; 214 }, 215 isImageExt : function(ext) 216 { 217 return (BX.message('bxImageExtensions') && BX.type.isNotEmptyString(ext) ? 218 (new RegExp('(?:^|\\W)(' + ext + ')(?:\\W|$)', 'gi')).test(BX.message('bxImageExtensions')) : 219 false 220 ); 221 }, 222 isImage : function(name, type, size) 223 { 224 size = BX.type.isNumber(size) ? size : (BX.type.isNotEmptyString(size) && !(/[\D]+/gi.test(size)) ? parseInt(size) : null); 225 return ( 226 (type === null || (type || '').indexOf("image/") === 0) && 227 (size === null || (size < 20 * 1024 * 1024)) && 228 BX.UploaderUtils.isImageExt((name || '').lastIndexOf('.') > 0 ? name.substr(name.lastIndexOf('.')+1).toLowerCase() : '')); 229 }, 230 scaleImage : function(arSourceSize, arSize, resizeType) 231 { 232 var sourceImageWidth = parseInt(arSourceSize["width"]), sourceImageHeight = parseInt(arSourceSize["height"]); 233 resizeType = (!resizeType && !!arSize["type"] ? arSize["type"] : resizeType); 234 arSize = (!!arSize ? arSize : {}); 235 arSize.width = parseInt(!!arSize.width ? arSize.width : 0); 236 arSize.height = parseInt(!!arSize.height ? arSize.height : 0); 237 238 var res = { 239 bNeedCreatePicture : false, 240 source : {x : 0, y : 0, width : 0, height : 0}, 241 destin : {x : 0, y : 0, width : 0, height : 0} 242 }, width, height; 243 244 if (!(sourceImageWidth > 0 || sourceImageHeight > 0)) 245 { 246 BX.DoNothing(); 247 } 248 else 249 {
250 if (!BX.type.isNotEmptyString(resizeType)) 251 { 252 resizeType = "inscribed"; 253 } 254 255 256 var ResizeCoeff, iResizeCoeff; 257 258 if (resizeType.indexOf("proportional") >= 0) 259 { 260 width = Math.max(sourceImageWidth, sourceImageHeight); 261 height = Math.min(sourceImageWidth, sourceImageHeight); 262 } 263 else 264 { 265 width = sourceImageWidth; 266 height = sourceImageHeight; 267 } 268 if (resizeType == "exact") 269 { 270 var 271 ratio = (sourceImageWidth / sourceImageHeight < arSize["width"] / arSize["height"] ? arSize["width"] / sourceImageWidth : arSize["height"] / sourceImageHeight), 272 x = Math.max(0, Math.round(sourceImageWidth / 2 - (arSize["width"] / 2) / ratio)), 273 y = Math.max(0, Math.round(sourceImageHeight / 2 - (arSize["height"] / 2) / ratio)); 274 275 res.bNeedCreatePicture = true; 276 res.coeff = ratio; 277 278 res.destin["width"] = arSize["width"]; 279 res.destin["height"] = arSize["height"]; 280 281 res.source["x"] = x; 282 res.source["y"] = y; 283 res.source["width"] = Math.round(arSize["width"] / ratio, 0); 284 res.source["height"] = Math.round(arSize["height"] / ratio, 0); 285 } 286 else 287 { 288 if (resizeType == "circumscribed") 289 { 290 ResizeCoeff = { 291 width : (width > 0 ? arSize["width"] / width : 1), 292 height: (height > 0 ? arSize["height"] / height : 1)}; 293 294 iResizeCoeff = Math.max(ResizeCoeff["width"], ResizeCoeff["height"], 1); 295 } 296 else 297 { 298 ResizeCoeff = { 299 width : (width > 0 ? arSize["width"] / width : 1), 300 height: (height > 0 ? arSize["height"] / height : 1)}; 301 302 iResizeCoeff = Math.min(ResizeCoeff["width"], ResizeCoeff["height"], 1); 303 iResizeCoeff = (0 < iResizeCoeff ? iResizeCoeff : 1); 304 } 305 res.bNeedCreatePicture = (iResizeCoeff != 1); 306 res.coeff = iResizeCoeff; 307 res.destin["width"] = Math.max(1, parseInt(iResizeCoeff * sourceImageWidth)); 308 res.destin["height"] = Math.max(1, parseInt(iResizeCoeff * sourceImageHeight)); 309 310 res.source["x"] = 0; 311 res.source["y"] = 0; 312 res.source["width"] = sourceImageWidth; 313 res.source["height"] = sourceImageHeight; 314 } 315 316 } 317 return res; 318 }, 319 dataURLToBlob : function(dataURL) 320 { 321 var marker = ';base64,', parts, contentType, raw, rawLength; 322 if(dataURL.indexOf(marker) == -1) { 323 parts = dataURL.split(','); 324 contentType = parts[0].split(':')[1]; 325 raw = parts[1]; 326 return new Blob([raw], {type: contentType}); 327 } 328 329 parts = dataURL.split(marker); 330 contentType = parts[0].split(':')[1]; 331 raw = window.atob(parts[1]); 332 rawLength = raw.length; 333 334 var uInt8Array = new Uint8Array(rawLength); 335 336 for(var i = 0; i < rawLength; ++i) { 337 uInt8Array[i] = raw.charCodeAt(i); 338 } 339 340 return new Blob([uInt8Array], {type: contentType}); 341 }, 342 sizeof : function(obj) { 343 var size = 0, key; 344 for (key in obj) { 345 if (obj.hasOwnProperty(key)) 346 { 347 size += key.length; 348 if (typeof obj[key] == "object") 349 { 350 if (obj[key] === null) 351 BX.DoNothing(); 352 else if (obj[key]["size"] > 0) 353 size += obj[key].size; 354 else 355 size += BX.UploaderUtils.sizeof(obj[key]); 356 } 357 else if (typeof obj[key] == "number") 358 { 359 size += obj[key].toString().length; 360 } 361 else if (!!obj[key] && obj[key].length > 0) 362 { 363 size += obj[key].length; 364 } 365 } 366 } 367 return size; 368 }, 369 FormToArray : function(form, data) 370 { 371 return BX.ajax.prepareForm(form, data); 372 }, 373 getFormattedSize : function (size, precision) 374 { 375 var a = ["b", "Kb", "Mb", "Gb", "Tb"], pos = 0; 376 while(size >= 1024 && pos < 4) 377 { 378 size /= 1024; 379 pos++; 380 } 381 return (Math.round(size * (precision > 0 ? precision * 10 : 1) ) / (precision > 0 ? precision * 10 : 1)) + 382 " " + BX.message("FILE_SIZE_" + a[pos]); 383 }, 384 bindEvents : function(obj, event, func) 385 { 386 var funcs = [], ii; 387 if (typeof func == "string") 388 { 389 eval('funcs.push(' + func + ');'); 390 } 391 else if (!!func["length"] && func["length"] > 0) 392 { 393 for(ii = 0; ii < func.length; ii++) 394 { 395 if (typeof func[ii] == "string") 396 eval('funcs.push(' + func[ii] + ');'); 397 else 398 funcs.push(func[ii]); 399 } 400 } 401 else 402 funcs.push(func); 403 if (funcs.length > 0) 404 { 405 for (ii = 0; ii < funcs.length; ii++) 406 { 407 BX.addCustomEvent(obj, event, funcs[ii]); 408 } 409 } 410 411 }, 412 applyFilePart : function(file, blob) 413 { 414 if (BX.type.isDomNode(file)) 415 { 416 file.uploadStatus = statuses.done; 417 } 418 else if (file == blob) 419 { 420 file.uploadStatus = statuses.done; 421 } 422 else if (file.blobed === true) 423 { 424 file.uploadStatus = ((file.package + 1) >= file.packages ? statuses.done : statuses.inprogress); 425 if (file.uploadStatus == statuses.inprogress) 426 file.package++; 427 } 428 return true; 429 }, 430 getFilePart : function(file, MaxFilesize) 431 { 432 var blob, chunkSize = MaxFilesize, start, end; 433 if (BX.type.isDomNode(file)) 434 { 435 blob = file; 436 } 437 else if (MaxFilesize <= 0 || file.size <= MaxFilesize) 438 { 439 blob = file; 440 } 441 else if (file['packages'] && file['packages'] <= file['package']) 442 { 443 blob = null; 444 } 445 else if (window.Blob || window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder) 446 { 447 if (file['packages']) 448 { 449 file.package++; 450 start = file.package * chunkSize; 451 end = start + chunkSize; 452 } 453 else 454 { 455 file.packages = Math.ceil(file.size / chunkSize); 456 file.package = 0; 457 start = 0; 458 end = chunkSize; 459 } 460 461 if('mozSlice' in file) 462 blob = file.mozSlice(start, end, file.type); 463 else if ('webkitSlice' in file) 464 blob = file.webkitSlice(start, end, file.type); 465 else if ('slice' in file) 466 blob = file.slice(start, end, file.type); 467 else 468 blob = file.Slice(start, end, file.type); 469 470 for (var ii in file) 471 { 472 if (file.hasOwnProperty(ii)) 473 { 474 blob[ii] = file[ii]; 475 } 476 } 477 blob["name"] = file["name"]; 478 blob["start"] = start; 479 blob["package"] = file.package; 480 blob["packages"] = file.packages; 481 } 482 return blob; 483 }, 484 makeAnArray : function(file, data) 485 { 486 file = (!!file ? file : {files : [], props : {}}); 487 var ii; 488 for (var jj in data) 489 { 490 if (data.hasOwnProperty(jj)) 491 { 492 if (typeof data[jj] == "object" && data[jj].length > 0) 493 { 494 file[jj] = (!!file[jj] ? file[jj] : []); 495 for (ii=0; ii<data[jj].length; ii++) 496 { 497 file[jj].push(data[jj][ii]); 498 } 499 } 500 else 501 { 502 503 for (ii in data[jj]) 504 { 505 if (data[jj].hasOwnProperty(ii)) 506 { 507 file[jj] = (!!file[jj] ? file[jj] : {}); 508 file[jj][ii] = data[jj][ii]; 509 } 510 } 511 } 512 } 513 } 514 return file; 515 }, 516 appendToForm : function(fd, key, val) 517 { 518 if (!!val && typeof val == "object") 519 { 520 for (var ii in val) 521 { 522 if (val.hasOwnProperty(ii)) 523 { 524 BX.UploaderUtils.appendToForm(fd, key + '[' + ii + ']', val[ii]); 525 } 526 } 527 } 528 else 529 {
530 fd.append(key, (!!val ? val : '')); 531 } 532 }, 533 FormData : function() 534 { 535 return new (BX.Uploader.getInstanceName() == "BX.UploaderSimple" ? FormDataLocal : window.FormData); 536 }, 537 prepareData : function(arData) 538 { 539 var data = {}; 540 if (null != arData) 541 { 542 if(typeof arData == 'object') 543 { 544 for(var i in arData) 545 { 546 if (arData.hasOwnProperty(i)) 547 { 548 var name = BX.util.urlencode(i); 549 if(typeof arData[i] == 'object') 550 data[name] = BX.UploaderUtils.prepareData(arData[i]); 551 else 552 data[name] = BX.util.urlencode(arData[i]); 553 } 554 } 555 } 556 else 557 data = BX.util.urlencode(arData); 558 } 559 return data; 560 } 561 }; 562 var FormDataLocal = function() 563 { 564 var uniqueID; 565 do { 566 uniqueID = Math.floor(Math.random() * 99999); 567 } while(BX("form-" + uniqueID)); 568 this.local = true; 569 this.form = BX.create("FORM", { 570 props: { 571 id: "form-" + uniqueID, 572 method: "POST", 573 enctype: "multipart/form-data", 574 encoding: "multipart/form-data" 575 }, 576 style: {display: "none"} 577 }); 578 document.body.appendChild(this.form); 579 }; 580 FormDataLocal.prototype = { 581 append : function(name, val) 582 { 583 if (BX.type.isDomNode(val)) 584 { 585 this.form.appendChild(val); 586 } 587 else 588 { 589 this.form.appendChild( 590 BX.create("INPUT", { 591 props : { 592 type : "hidden", 593 name : name, 594 value : val 595 } 596 } 597 ) 598 ); 599 } 600 } 601 }; 602 BX.UploaderUtils.slice = function(file, start, end) 603 { 604 var blob = null; 605 if('mozSlice' in file) 606 blob = file.mozSlice(start, end); 607 else if ('webkitSlice' in file) 608 blob = file.webkitSlice(start, end); 609 else if ('slice' in file) 610 blob = file.slice(start, end); 611 else 612 blob = file.Slice(start, end, file.type); 613 return blob; 614 }; 615 BX.UploaderUtils.readFile = function (file, callback, method) 616 { 617 if (window["FileReader"]) 618 { 619 var fileReader = new FileReader(); 620 fileReader.onload = fileReader.onerror = callback; 621 method = (method || 'readAsDataURL'); 622 if (fileReader[method]) 623 { 624 fileReader[method](file); 625 return fileReader; 626 } 627 } 628 return false; 629 }; 630}(window)); 631 632/* End */ 633; 634; /* Start:"a:4:{s:4:"full";s:63:"/bitrix/js/main/core/core_uploader/uploader.js?1786943472100786";s:6:"source";s:46:"/bitrix/js/main/core/core_uploader/uploader.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/ 635(function (exports,main_core,main_core_events) { 636 'use strict'; 637 638 function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; } 639 640 function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } } 641 642 function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "get"); return _classApplyDescriptorGet(receiver, descriptor); } 643 644 function _classCheckPrivateStaticFieldDescriptor(descriptor, action) { if (descriptor === undefined) { throw new TypeError("attempted to " + action + " private static field before its declaration"); } } 645 646 function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } } 647 648 function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } 649 650 var Options = /*#__PURE__*/function () { 651 function Options() { 652 babelHelpers.classCallCheck(this, Options); 653 } 654 655 babelHelpers.createClass(Options, null, [{ 656 key: "getEventName", 657 value: function getEventName(eventName) { 658 return [this.getEventNamespace()].concat(babelHelpers.toConsumableArray(eventName)).join(':'); 659 } 660 }, { 661 key: "getEventNamespace", 662 value: function getEventNamespace() { 663 return 'BX:Main:Uploader:'; 664 } 665 }, { 666 key: "calibratePostSize", 667 value: function calibratePostSize(deltaTime, size) { 668 if (deltaTime <= 0) { 669 return; 670 } 671 672 if (deltaTime < this.defaultSettings['estimatedTimeForUploadFile']) { 673 var sizes = [this.defaultSettings['currentPostSize'] * 2, this.defaultSettings["phpPostMaxSize"]]; 674 675 if (size > 0) { 676 sizes.push(Math.ceil(size * this.defaultSettings['estimatedTimeForUploadFile'] * 1000 / deltaTime)); 677 } 678 679 this.defaultSettings['currentPostSize'] = Math.min.apply(Math, sizes); 680 } else { 681 this.defaultSettings['currentPostSize'] = Math.max(Math.ceil(this.defaultSettings['currentPostSize'] / 2), this.defaultSettings['phpPostMinSize']); 682 } 683 684 this.defaultSettings['currentPostSize'] = Math.max(this.defaultSettings['currentPostSize'], this.defaultSettings['phpPostMinSize']); 685 } 686 }, { 687 key: "getUploadLimits", 688 value: function getUploadLimits(key) { 689 if (!this.defaultSettings) { 690 this.defaultSettings = { 691 currentPostSize: 5.5 * 1024 * 1024, 692 phpPostMinSize: 5.5 * 1024 * 1024, 693 // Bytes 694 phpUploadMaxFilesize: Math.min(/^d+$/.test(main_core.Loc.getMessage('phpUploadMaxFilesize')) ? main_core.Loc.getMessage('phpUploadMaxFilesize') : 5 * 1024 * 1024, 5 * 1024 * 1024), 695 // Bytes 5MB because of Cloud 696 phpMaxFileUploads: Math.max(/^d+$/.test(main_core.Loc.getMessage('phpMaxFileUploads')) ? main_core.Loc.getMessage('phpMaxFileUploads') : 20, 20), 697 phpPostMaxSize: /^d+$/.test(main_core.Loc.getMessage('phpPostMaxSize')) ? main_core.Loc.getMessage('phpPostMaxSize') : 11 * 1024 * 1024, 698 // Bytes 699 estimatedTimeForUploadFile: 10 * 60, 700 // in sec 701 maxSize: this.getMaxSize() 702 }; 703 } 704 705 if (key) { 706 return this.defaultSettings[key]; 707 } 708 709 return this.defaultSettings; 710 } 711 }, { 712 key: "getFileTypes", 713 value: function getFileTypes() { 714 return ['A', //'A'll files 715 'I', //'I'mages 716 'F' //'F'iles with selected extensions 717 ]; 718 } 719 }, { 720 key: "getImageExtensions", 721 value: function getImageExtensions() { 722 return ["jpg", "bmp", "jpeg", "jpe", "gif", "png", "webp"]; 723 } 724 }, { 725 key: "getMaxSize", 726 value: function getMaxSize() { 727 if (_classStaticPrivateFieldSpecGet(this, Options, _quota) !== null && !_classStaticPrivateFieldSpecGet(this, Options, _quota)) { 728 if (/^\d+$/.test(main_core.Loc.getMessage("bxQuota"))) { 729 _classStaticPrivateFieldSpecSet(this, Options, _quota, parseInt(main_core.Loc.getMessage("bxQuota"))); 730 } else { 731 _classStaticPrivateFieldSpecSet(this, Options, _quota, null); 732 } 733 } 734 735 return _classStaticPrivateFieldSpecGet(this, Options, _quota); 736 } 737 }, { 738 key: "decrementMaxSize", 739 value: function decrementMaxSize(size) { 740 if (this.getMaxSize() !== null) { 741 _classStaticPrivateFieldSpecSet(this, Options, _quota, _classStaticPrivateFieldSpecGet(this, Options, _quota) - size); 742 } 743 744 return _classStaticPrivateFieldSpecGet(this, Options, _quota); 745 } 746 }, { 747 key: "getMaxTimeToUploading", 748 value: function getMaxTimeToUploading() { 749 return 900; 750 } 751 }, { 752 key: "getVersion", 753 value: function getVersion() { 754 return '1'; 755 } 756 }]); 757 return Options; 758 }(); 759 760 babelHelpers.defineProperty(Options, "defaultSettings", null); 761 var _quota = { 762 writable: true, 763 value: void 0 764 }; 765 babelHelpers.defineProperty(Options, "uploadStatus", { 766 ready: 'upload is ready', 767 preparing: 'upload is not started, but preparing', 768 inProgress: 'upload is in active streaming', 769 done: 'upload is in successfully done', 770 error: 'upload is in finished with errors', 771 stopped: 'PAUSE' 772 }); 773 babelHelpers.defineProperty(Options, "fileStatus", { 774 ready: 'fileIsReady', 775 removed: 'fileIsRemoved', 776 restored: 'fileIsRestored', 777 errored: 'fileIsBad' 778 }); 779 780 var DropZone = /*#__PURE__*/function () { 781 function DropZone(dropZoneNode) { 782 babelHelpers.classCallCheck(this, DropZone); 783 784 if (main_core.Type.isStringFilled(dropZoneNode)) { 785 dropZoneNode = document.getElementById(dropZoneNode); 786 } 787 788 if (main_core.Type.isDomNode(dropZoneNode) && BX.DD && BX.ajax.FormData.isSupported()) { 789 this.initialize(dropZoneNode); 790 } 791 } 792 793 babelHelpers.createClass(DropZone, [{ 794 key: "initialize", 795 value: function initialize(dropZoneNode) { 796 var _this = this; 797 798 this.dndObject = new BX.DD.dropFiles(dropZoneNode); 799 800 if (!this.dndObject || !this.dndObject.supported()) { 801 return; 802 } 803 804 var handlers = { 805 dropFiles: function dropFiles(_ref) { 806 var _ref$compatData = babelHelpers.slicedToArray(_ref.compatData, 2), 807 files = _ref$compatData[0], 808 e = _ref$compatData[1]; 809 810 if (e && e["dataTransfer"] && e["dataTransfer"]["items"] && e["dataTransfer"]["items"].length > 0) { 811 var replaceFileArray = false;
812 var fileCopies = []; 813 var item; 814 815 for (var i = 0; i < e["dataTransfer"]["items"].length; i++) { 816 item = e["dataTransfer"]["items"][i]; 817 818 if (item["webkitGetAsEntry"] && item["getAsFile"]) { 819 replaceFileArray = true; 820 var entry = item["webkitGetAsEntry"](); 821 822 if (entry && entry.isFile) { 823 fileCopies.push(item["getAsFile"]()); 824 } 825 } 826 } 827 828 if (replaceFileArray) files = fileCopies; 829 } 830 831 main_core_events.EventEmitter.emit(_this, Options.getEventName('caught'), { 832 files: files 833 }); 834 }, 835 dragEnter: function dragEnter(_ref2) { 836 var _ref2$compatData = babelHelpers.slicedToArray(_ref2.compatData, 1), 837 e = _ref2$compatData[0]; 838 839 var isFileTransfer = false; 840 841 if (e && e["dataTransfer"] && e["dataTransfer"]["types"]) { 842 for (var i = 0; i < e["dataTransfer"]["types"].length; i++) { 843 if (e["dataTransfer"]["types"][i] === "Files") { 844 isFileTransfer = true; 845 break; 846 } 847 } 848 } 849 850 if (isFileTransfer) { 851 _this.dndObject.DIV.classList.add('bxu-file-input-over'); 852 853 BX.onCustomEvent(_this, 'dragEnter', [e]); // compatibility event 854 } 855 }, 856 dragLeave: function dragLeave(_ref3) { 857 var _ref3$compatData = babelHelpers.slicedToArray(_ref3.compatData, 1), 858 e = _ref3$compatData[0]; 859 860 _this.dndObject.DIV.classList.remove('bxu-file-input-over'); 861 862 BX.onCustomEvent(_this, 'dragLeave', [e]); // compatibility event 863 } 864 }; 865 main_core_events.EventEmitter.subscribe(this.dndObject, 'dropFiles', handlers.dropFiles); 866 main_core_events.EventEmitter.subscribe(this.dndObject, 'dragEnter', handlers.dragEnter); 867 main_core_events.EventEmitter.subscribe(this.dndObject, 'dragLeave', handlers.dragLeave); 868 } 869 }, { 870 key: "destroy", 871 value: function destroy() { 872 main_core_events.EventEmitter.unsubscribeAll(this.dndObject); 873 delete this.dndObject.DIV; 874 delete this.dndObject; 875 } 876 }]); 877 return DropZone; 878 }(); 879 880 var buildAjaxPromiseToRestoreCsrf = function buildAjaxPromiseToRestoreCsrf(config, withoutRestoringCsrf) { 881 withoutRestoringCsrf = withoutRestoringCsrf || false; 882 var originalConfig = Object.assign({}, config); 883 var request = null; 884 885 config.onrequeststart = function (xhr) { 886 request = xhr; 887 }; 888 889 var promise = BX.ajax.promise(config); 890 return promise.then(function (response) { 891 if (!withoutRestoringCsrf && main_core.Type.isPlainObject(response) && response['errors']) { 892 var csrfProblem = false; 893 response.errors.forEach(function (error) { 894 if (error.code === 'invalid_csrf' && error.customData.csrf) { 895 BX.message({ 896 'bitrix_sessid': error.customData.csrf 897 }); 898 originalConfig.headers = originalConfig.headers || []; 899 originalConfig.headers = originalConfig.headers.filter(function (header) { 900 return header && header.name !== 'X-Bitrix-Csrf-Token'; 901 }); 902 originalConfig.headers.push({ 903 name: 'X-Bitrix-Csrf-Token', 904 value: BX.bitrix_sessid() 905 }); 906 csrfProblem = true; 907 } 908 }); 909 910 if (csrfProblem) { 911 return buildAjaxPromiseToRestoreCsrf(originalConfig, true); 912 } 913 } 914 915 return response; 916 }).then(function (response) { 917 var assetsLoaded = new BX.Promise(); 918 assetsLoaded.fulfill(response); 919 return assetsLoaded; 920 }).catch(function (_ref) { 921 var reason = _ref.reason, 922 data = _ref.data; 923 924 if (reason === 'status' && data && (String(data).indexOf('503') >= 0 || String(data).indexOf('504') >= 0)) { 925 originalConfig['50xCounter'] = (originalConfig['50xCounter'] || 0) + 1; 926 927 if (originalConfig['50xCounter'] <= 2) { 928 var headers = request.getAllResponseHeaders().trim().split(/[\r\n]+/); 929 var headerMap = {};
930 headers.forEach(function (line) { 931 var parts = line.split(': '); 932 var header = parts.shift().toLowerCase(); 933 headerMap[header] = parts.join(': '); 934 }); 935 var timeoutSec = null; 936 937 if (headerMap['retry-after'] && /\d+/.test(headerMap['retry-after'])) { 938 timeoutSec = parseInt(headerMap['retry-after']); 939 } 940 941 var p = new BX.Promise(); 942 setTimeout(function () { 943 p.fulfill(); 944 }, (timeoutSec || 20) * 1000); 945 return p.then(function () { 946 return buildAjaxPromiseToRestoreCsrf(originalConfig); 947 }); 948 } 949 } 950 951 var ajaxReject = new BX.Promise(); 952 953 if (main_core.Type.isPlainObject(data) && data.status && data.hasOwnProperty('data')) { 954 ajaxReject.reject(data); 955 } else { 956 ajaxReject.reject({ 957 status: 'error', 958 data: { 959 ajaxRejectData: data 960 }, 961 errors: [{ 962 code: 'NETWORK_ERROR', 963 message: 'Network error' 964 }] 965 }); 966 } 967 968 return ajaxReject; 969 }); 970 }; 971 972 var Stream = /*#__PURE__*/function (_EventEmitter) { 973 babelHelpers.inherits(Stream, _EventEmitter); 974 975 function Stream() { 976 var _this; 977 978 babelHelpers.classCallCheck(this, Stream); 979 _this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Stream).call(this)); 980 981 _this.setEventNamespace(Options.getEventNamespace()); 982 983 _this.onprogress = _this.onprogress.bind(babelHelpers.assertThisInitialized(_this)); 984 _this.onprogressupload = _this.onprogressupload.bind(babelHelpers.assertThisInitialized(_this)); 985 return _this; 986 } 987 988 babelHelpers.createClass(Stream, [{ 989 key: "send", 990 value: function send(url, formData) { 991 var _this2 = this; 992 993 this.deltaTime = -1 * new Date().getTime(); 994 this.totalSize = null; 995 buildAjaxPromiseToRestoreCsrf({ 996 method: 'POST', 997 dataType: 'json', 998 url: url, 999 data: formData, 1000 timeout: Options.getMaxTimeToUploading(), 1001 preparePost: false, 1002 headers: [{ 1003 name: 'X-Bitrix-Csrf-Token', 1004 value: BX.bitrix_sessid() 1005 }, { 1006 name: 'X-Bitrix-Site-Id', 1007 value: BX.message.SITE_ID || '' 1008 }], 1009 onprogress: this.onprogress, 1010 onprogressupload: this.onprogressupload 1011 }).then(function (response) { 1012 _this2.done({ 1013 status: 'success', 1014 data: response 1015 }); 1016 }).catch(function (_ref2) { 1017 var errors = _ref2.errors, 1018 data = _ref2.data; 1019 1020 _this2.done({ 1021 status: 'failed', 1022 errors: errors.map(function (_ref3) { 1023 var code = _ref3.code, 1024 message = _ref3.message; 1025 return message; 1026 }), 1027 data: data 1028 }); 1029 }).catch(function (response) { 1030 _this2.done({ 1031 status: 'failed', 1032 errors: ['Unexpected server response.'], 1033 data: response 1034 }); 1035 }); 1036 } 1037 }, { 1038 key: "onprogress", 1039 value: function onprogress(e) {} 1040 }, { 1041 key: "onprogressupload", 1042 value: function onprogressupload(e) { 1043 var procent = 5; 1044 1045 if (babelHelpers.typeof(e) == "object" && e.lengthComputable) { 1046 procent = e.loaded * 100 / (e["total"] || e["totalSize"]); 1047 this.totalSize = e["total"] || e["totalSize"]; 1048 } else if (e > procent) procent = e; 1049 1050 procent = procent > 5 ? procent : 5; 1051 this.emit('progress', procent); 1052 } 1053 }, { 1054 key: "done", 1055 value: function done(response) { 1056 this.deltaTime += new Date().getTime(); 1057 Options.calibratePostSize(this.deltaTime, this.totalSize); 1058 this.emit('done', response); 1059 } 1060 }, { 1061 key: "destroy", 1062 value: function destroy() { 1063 console.log('Clear all from stream'); 1064 } 1065 }]); 1066 return Stream; 1067 }(main_core_events.EventEmitter); 1068 1069 function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } 1070 1071 function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } } 1072 1073 var _currentFileToUpload = /*#__PURE__*/new WeakMap(); 1074 1075 var PackageFile = /*#__PURE__*/function (_EventEmitter) { 1076 babelHelpers.inherits(PackageFile, _EventEmitter); 1077 1078 //null|ready 1079 //null|inprogress|done|errored 1080 function PackageFile(item, pack) { 1081 var _this; 1082 1083 babelHelpers.classCallCheck(this, PackageFile); 1084 _this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(PackageFile).call(this)); 1085 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "isReadyToPack", true); 1086 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "packStatus", null); 1087 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "packPercent", 0); 1088 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "uploadStatus", null); 1089 1090 _classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _currentFileToUpload, { 1091 writable: true, 1092 value: null 1093 }); 1094 1095 _this.setEventNamespace(Options.getEventNamespace()); 1096 1097 _this.item = item; // item with a node 1098 1099 _this.id = item.getId(); 1100 _this.name = item.name; 1101 _this.fileStatus = Options.fileStatus.ready; // ready|remove|restore 1102 1103 _this.isReadyToPack = item.preparationStatus === _this.constructor.preparationStatusIsDone; 1104 _this.copiesCount = item.getThumbs("getCount") + 1; 1105 main_core_events.EventEmitter.subscribeOnce(item, 'onFileIsDeleted', function () { 1106 _this.fileStatus = Options.fileStatus.removed; 1107 }); 1108 1109 if (!_this.isReadyToPack) { 1110 main_core_events.EventEmitter.subscribeOnce(item, 'onFileIsPrepared', function () { 1111 _this.isReadyToPack = true; 1112
1113 _this.emit('onReady'); 1114 }); 1115 main_core_events.EventEmitter.emit(item, 'onFileHasToBePrepared', new main_core_events.BaseEvent({ 1116 compatData: [item.getId(), item] 1117 })); 1118 } 1119 1120 return _this; 1121 } 1122 1123 babelHelpers.createClass(PackageFile, [{ 1124 key: "isReady", 1125 value: function isReady() { 1126 return this.isReadyToPack; 1127 } 1128 }, { 1129 key: "isRemoved", 1130 value: function isRemoved() { 1131 return this.fileStatus === Options.fileStatus.removed; 1132 } 1133 }, { 1134 key: "isPacked", 1135 value: function isPacked() { 1136 return this.packStatus === Options.uploadStatus.done; 1137 } 1138 }, { 1139 key: "getId", 1140 value: function getId() { 1141 return this.id; 1142 } 1143 }, { 1144 key: "markAsPacked", 1145 value: function markAsPacked(percentToIncrement) { 1146 if (percentToIncrement === true) { 1147 this.packStatus = Options.uploadStatus.done; 1148 this.packPercent = 100; 1149 } else { 1150 this.packPercent += percentToIncrement / this.copiesCount; 1151 this.packPercent = this.packPercent > 100 ? 100 : this.packPercent; 1152 } 1153 } 1154 }, { 1155 key: "packFile", 1156 value: function packFile() { 1157 var result = { 1158 error: false, 1159 done: true, 1160 data: null 1161 }; 1162 1163 if (this.isRemoved()) { 1164 result.data = { 1165 removed: 'Y', 1166 name: this.name 1167 }; 1168 this.markAsPacked(true); 1169 } 1170 1171 if (this.isPacked()) { 1172 return result; 1173 } 1174 1175 var currentBlob; 1176 var copyName = 'default'; 1177 1178 if (this.packStatus === null) { 1179 result.data = this.item.getProps() || { 1180 name: this.name 1181 }; 1182 1183 if (this.item['restored']) { 1184 result.data['restored'] = this.item['restored']; 1185 delete this.item['restored']; 1186 } 1187 1188 this.packStatus = Options.uploadStatus.inProgress; 1189 currentBlob = this.item["file"]; 1190 } else if (babelHelpers.classPrivateFieldGet(this, _currentFileToUpload) instanceof Blob) { 1191 currentBlob = babelHelpers.classPrivateFieldGet(this, _currentFileToUpload); 1192 babelHelpers.classPrivateFieldSet(this, _currentFileToUpload, null); 1193 } else { 1194 currentBlob = this.item.getThumbs(null); 1195 1196 if (currentBlob === null) { 1197 this.markAsPacked(true); 1198 return result; 1199 } 1200 1201 copyName = currentBlob['thumb']; 1202 } 1203 1204 var packingPercent = 100; 1205 1206 if (currentBlob instanceof Blob) // Regular behaviour 1207 { 1208 var blob = BX.UploaderUtils.getFilePart(currentBlob, Options.getUploadLimits('phpUploadMaxFilesize')); 1209 1210 if (blob && blob !== currentBlob) { 1211 if (blob.packages - blob.package > 1) { 1212 babelHelpers.classPrivateFieldSet(this, _currentFileToUpload, currentBlob); 1213 } 1214 1215 packingPercent = blob.size / currentBlob.size * 100; 1216 copyName = [copyName, '.ch', blob.package, '.', (blob.start > 0 ? blob.start : "0") + '.chs' + blob.packages].join(''); 1217 blob.name = copyName; 1218 } 1219 1220 currentBlob = blob; 1221 } 1222 1223 if (currentBlob) { 1224 result.data = result.data || { 1225 name: this.name 1226 }; 1227 1228 if (currentBlob instanceof Blob) { 1229 result.data[copyName] = currentBlob; 1230 } else { 1231 result.data['files'] = result.data['files'] || {}; 1232 result.data['files'][copyName] = currentBlob; 1233 } 1234 } 1235 1236 if (result.data) { 1237 result.done = false; 1238 this.markAsPacked(packingPercent); 1239 } else { 1240 this.markAsPacked(true); 1241 } 1242 1243 return result; 1244 } 1245 }, { 1246 key: "parseResponse", 1247 value: function parseResponse(_ref) {// console.log('parseResponse: ', this.getId(), file); 1248 1249 var file = _ref.file, 1250 hash = _ref.hash, 1251 status = _ref.status; 1252 } 1253 }, { 1254 key: "size", 1255 get: function get() { 1256 return this.item ? this.item.size || 0 : 0; 1257 } 1258 }]); 1259 return PackageFile; 1260 }(main_core_events.EventEmitter); 1261 1262 babelHelpers.defineProperty(PackageFile, "preparationStatusIsDone", 4); 1263 1264 var getFormDataSize = function getFormDataSize(formData) { 1265 var entries = formData.entries(); 1266 var entry, 1267 filesCount = 0, 1268 formSize = 0; 1269 1270 while ((entry = entries.next()) && entry.done === false) { 1271 var _entry$value = babelHelpers.slicedToArray(entry.value, 2), 1272 name = _entry$value[0], 1273 value = _entry$value[1]; 1274 1275 if (value instanceof Blob) { 1276 filesCount++; 1277 formSize += value.size; 1278 } else { 1279 formSize += value.toString().length; 1280 } 1281 1282 formSize += name.toString().length; 1283 } 1284 1285 return [formSize, filesCount]; 1286 }; 1287 1288 var convertFormDataToObject = function convertFormDataToObject(formData) { 1289 var entries = formData.entries(); 1290 var entry; 1291 var data = {}; 1292 1293 while ((entry = entries.next()) && entry.done === false) { 1294 var _entry$value2 = babelHelpers.slicedToArray(entry.value, 2), 1295 name = _entry$value2[0], 1296 value = _entry$value2[1]; 1297 1298 if (name.indexOf('[') <= 0) { 1299 data[name] = value; 1300 } else { 1301 (function () { 1302 var names = [name.substring(0, name.indexOf('['))]; 1303 name.replace(/\[(.*?)\]/gi, function (n, nn) { 1304 names.push(nn.length > 0 ? nn : ''); 1305 }); 1306 var n = void 0; 1307 var pointer = data; 1308 1309 while (n = names.shift()) { 1310 if (n === '') { 1311 pointer.push(value); 1312 break; 1313 } else if (names.length <= 0) { 1314 pointer[n] = value; 1315 break; 1316 } else if (names[0] === '') { 1317 pointer[n] = pointer[n] || []; 1318 pointer = pointer[n]; 1319 } else { 1320 pointer[n] = pointer[n] || {}; 1321 pointer = pointer[n]; 1322 } 1323 } 1324 })(); 1325 } 1326 } 1327 1328 return data; 1329 }; 1330 1331 var copyFormToForm = function copyFormToForm(fromData1, formData2) { 1332 var entries = fromData1.entries(); 1333 var entry; 1334 1335 while ((entry = entries.next()) && entry.done === false) { 1336 var _entry$value3 = babelHelpers.slicedToArray(entry.value, 2), 1337 name = _entry$value3[0], 1338 value = _entry$value3[1]; 1339 1340 if (value instanceof Blob) { 1341 formData2.append(name, value, value.name); 1342 } else { 1343 formData2.append(name, value); 1344 } 1345 } 1346 }; 1347 1348 var appendToForm = function appendToForm(formData, ob, prefix) { 1349 for (var ii in ob) { 1350 if (ob.hasOwnProperty(ii)) { 1351 var name = (prefix ? prefix + '[#name#]' : '#name#').replace('#name#', ii); 1352 1353 if (main_core.Type.isPlainObject(ob[ii])) { 1354 appendToForm(formData, ob[ii], name); 1355 } else { 1356 if (ob[ii] instanceof Blob) { 1357 formData.append(name, ob[ii], ob[ii]['name'] || ii); 1358 } else { 1359 formData.append(name, ob[ii]); 1360 } 1361 } 1362 } 1363 } 1364 }; 1365 1366 function _classPrivateFieldInitSpec$1(obj, privateMap, value) { _checkPrivateRedeclaration$1(obj, privateMap); privateMap.set(obj, value); } 1367 1368 function _checkPrivateRedeclaration$1(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } } 1369 1370 var _formDataFilesCount = /*#__PURE__*/new WeakMap(); 1371 1372 var _formDataSize = /*#__PURE__*/new WeakMap(); 1373 1374 var Package = /*#__PURE__*/function (_EventEmitter) { 1375 babelHelpers.inherits(Package, _EventEmitter); 1376 1377 function Package(_ref) { 1378 var _this; 1379 1380 var id = _ref.id, 1381 formData = _ref.formData, 1382 files = _ref.files, 1383 uploadFileUrl = _ref.uploadFileUrl, 1384 uploadInputName = _ref.uploadInputName; 1385 babelHelpers.classCallCheck(this, Package); 1386 _this = babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Package).call(this)); 1387 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "length", 0); 1388 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "filesVirgin", new Set()); 1389 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "filesInprogress", new Set()); 1390 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "files", new Map()); 1391 1392 _classPrivateFieldInitSpec$1(babelHelpers.assertThisInitialized(_this), _formDataFilesCount, { 1393 writable: true, 1394 value: 0 1395 }); 1396 1397 _classPrivateFieldInitSpec$1(babelHelpers.assertThisInitialized(_this), _formDataSize, { 1398 writable: true, 1399 value: 0 1400 }); 1401 1402 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "makeAPackTimeout", 0); 1403 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "uploadStatus", Options.uploadStatus.ready); 1404 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "errors", []); 1405 babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "response", { 1406 status: 'start' 1407 }); 1408 1409 _this.setEventNamespace(Options.getEventNamespace()); 1410 1411 _this.id = id; 1412 _this.formData = formData; 1413 _this.uploadFileUrl = uploadFileUrl; 1414 _this.uploadInputName = uploadInputName; 1415 1416 _this.initFiles(files); 1417 1418 console.log('2. Package is created with ', _this.filesVirgin.size, ' files.'); 1419 _this.doneStreaming = _this.doneStreaming.bind(babelHelpers.assertThisInitialized(_this)); 1420 _this.progressStreaming = _this.progressStreaming.bind(babelHelpers.assertThisInitialized(_this)); 1421 return _this; 1422 } 1423 1424 babelHelpers.createClass(Package, [{ 1425 key: "getId", 1426 value: function getId() { 1427 return this.id; 1428 } 1429 }, { 1430 key: "initFiles", 1431 value: function initFiles(files) { 1432 var _this2 = this; 1433
1434 files.forEach(function (fileItem) { 1435 var uploadFile = new PackageFile(fileItem); 1436 1437 _this2.filesVirgin.add(uploadFile.getId()); 1438 1439 _this2.files.set(uploadFile.getId(), uploadFile); 1440 }); 1441 } 1442 }, { 1443 key: "prepare", 1444 value: function prepare() { 1445 var _getFormDataSize = getFormDataSize(this.formData), 1446 _getFormDataSize2 = babelHelpers.slicedToArray(_getFormDataSize, 2), 1447 formSize = _getFormDataSize2[0], 1448 filesCount = _getFormDataSize2[1]; 1449 1450 console.log('2.1 Prepare form with files: ', filesCount, ' and formSize: ', parseInt(formSize), 'B'); 1451 1452 if (Options.getUploadLimits('phpMaxFileUploads') <= filesCount) { 1453 this.error('Too many files in your form. '); 1454 return false; 1455 } 1456 1457 if (Options.getUploadLimits('phpPostMaxSize') - formSize < Options.getUploadLimits('phpPostMinSize')) { 1458 this.error('Too much data in your form. '); 1459 return false; 1460 } 1461 1462 var packSize = 0; 1463 this.files.forEach(function (file) { 1464 packSize += file.size; 1465 }); 1466 1467 if (Options.getMaxSize() !== null && Options.getMaxSize() < packSize) { 1468 this.error('There is not enough space on your server.'); 1469 return false; 1470 } 1471 1472 Options.decrementMaxSize(packSize); 1473 babelHelpers.classPrivateFieldSet(this, _formDataSize, formSize); 1474 babelHelpers.classPrivateFieldSet(this, _formDataFilesCount, filesCount); 1475 return true; 1476 } 1477 }, { 1478 key: "run", 1479 value: function run(stream) { 1480 if (this.uploadStatus !== Options.uploadStatus.ready) { 1481 return; 1482 } 1483 1484 console.log('4. Package is running with a stream: ', stream); 1485 this.uploadStatus = Options.uploadStatus.preparing; 1486 return this.startStreaming(stream); 1487 } 1488 }, { 1489 key: "bindStream", 1490 value: function bindStream(stream) { 1491 if (stream === this.stream) { 1492 return; 1493 } 1494 1495 this.stream = stream; 1496 stream.subscribe('done', this.doneStreaming); 1497 stream.subscribe('progress', this.progressStreaming); 1498 } 1499 }, { 1500 key: "unbindStream", 1501 value: function unbindStream(stream) { 1502 if (stream || this.stream) { 1503 (stream || this.stream).unsubscribe('done', this.doneStreaming); 1504 (stream || this.stream).unsubscribe('progress', this.progressStreaming); 1505 1506 if (stream === this.stream) { 1507 delete this.stream; 1508 } 1509 } 1510 } 1511 }, { 1512 key: "makeAPack", 1513 value: function makeAPack(formSize, filesCount, formData) { 1514 var _this3 = this; 1515 1516 while (formSize - Options.getUploadLimits('phpUploadMaxFilesize') > 0 && filesCount > 0) { 1517 if (this.filesVirgin.size <= 0) { 1518 break; 1519 } 1520 1521 var entry = this.filesVirgin.entries().next(); 1522 1523 if (entry.done === true) { 1524 break; 1525 } 1526 /*@var uploadItem: PackageFile */ 1527 1528 1529 var _entry$value = babelHelpers.slicedToArray(entry.value, 1), 1530 uploadItemId = _entry$value[0]; 1531 1532 var uploadItem = this.files.get(uploadItemId); 1533 1534 if (!uploadItem.isReady()) { 1535 return uploadItem.subscribeOnce('onReady', function () { 1536 _this3.makeAPack(formSize, filesCount, formData); 1537 }); 1538 } 1539 1540 var result = uploadItem.packFile(); 1541 1542 if (result.data) { 1543 var name = "".concat(this.uploadInputName, "[").concat(uploadItem.getId(), "]"); 1544 var tmpFormData = new FormData(); 1545 appendToForm(tmpFormData, result.data, name); 1546 1547 var _getFormDataSize3 = getFormDataSize(tmpFormData), 1548 _getFormDataSize4 = babelHelpers.slicedToArray(_getFormDataSize3, 2), 1549 tmpFormSize = _getFormDataSize4[0], 1550 tmpFilesCount = _getFormDataSize4[1]; 1551 1552 copyFormToForm(tmpFormData, formData); 1553 formSize -= tmpFormSize; 1554 filesCount -= tmpFilesCount; 1555 this.filesInprogress.add(uploadItemId); 1556 } 1557 1558 if (result.done === true) { 1559 this.filesVirgin.delete(uploadItemId); 1560 } 1561 } 1562
1563 return this.emit('onPackIsReady', formData); 1564 } 1565 }, { 1566 key: "startStreaming", 1567 value: function startStreaming(stream) { 1568 this.bindStream(stream); 1569 this.doStreaming(stream); 1570 } 1571 }, { 1572 key: "doStreaming", 1573 value: function doStreaming(stream) { 1574 var _this4 = this; 1575 1576 this.subscribeOnce('onPackIsReady', function (_ref2) { 1577 var data = _ref2.data; 1578 console.log('onPackIsReady: ', data); 1579 console.groupEnd('Make a pack.'); 1580 clearTimeout(_this4.makeAPackTimeout); 1581 _this4.makeAPackTimeout = 0; 1582 1583 if (data instanceof FormData) { 1584 var firstValue = data.entries().next(); 1585 1586 if (firstValue.done === true && !firstValue.value) { 1587 return _this4.checkAndDone(stream); 1588 } 1589 1590 copyFormToForm(_this4.formData, data); 1591 console.log('4.1. Start streaming'); 1592 return stream.send(_this4.uploadFileUrl, data); 1593 } 1594 1595 _this4.error('Package: error in packing'); 1596 }); 1597 var formSize = Math.min(Options.getUploadLimits('currentPostSize'), Options.getUploadLimits('phpPostMaxSize') - babelHelpers.classPrivateFieldGet(this, _formDataSize)); 1598 var filesCount = Options.getUploadLimits('phpMaxFileUploads') - babelHelpers.classPrivateFieldGet(this, _formDataFilesCount); 1599 var fromData = new FormData(); 1600 console.group('Make a pack.'); 1601 this.makeAPack(formSize, filesCount, fromData); 1602 this.makeAPackTimeout = setTimeout(function () { 1603 _this4.emit('onPackIsReady', null); 1604 }, Options.getUploadLimits('estimatedTimeForUploadFile') * 1000); 1605 } 1606 }, { 1607 key: "doneStreaming", 1608 value: function doneStreaming(_ref3) { 1609 var stream = _ref3.target, 1610 _ref3$data = _ref3.data, 1611 status = _ref3$data.status, 1612 data = _ref3$data.data, 1613 errors = _ref3$data.errors; 1614 console.log('4.2. Done streaming'); 1615 1616 if (status === 'success') { 1617 this.parseResponse(data); 1618 1619 if (this.errors.length <= 0) { 1620 this.doStreaming(stream); 1621 } 1622 } else { 1623 this.error(errors.join('. ')); 1624 } 1625 } 1626 }, { 1627 key: "progressStreaming", 1628 value: function progressStreaming(_ref4) { 1629 var _this5 = this; 1630 1631 var percent = _ref4.data; 1632 this.filesInprogress.forEach(function (itemId) { 1633 var item = _this5.files.get(itemId); 1634 1635 var currentPercent = percent * (item.packPercent || 0); 1636 1637 if (!item['previousPackPercent']) { 1638 item['previousPackPercent'] = currentPercent; 1639 } 1640 1641 _this5.emit('fileIsInProgress', { 1642 itemId: itemId, 1643 item: item.item, 1644 percent: Math.ceil(Math.max(item['previousPackPercent'], currentPercent) / 100) 1645 }); 1646 1647 item['previousPackPercent'] = currentPercent; 1648 }); 1649 } 1650 }, { 1651 key: "parseResponse", 1652 value: function parseResponse(data) { 1653 var _this6 = this; 1654 1655 var merge = function merge(ar1, ar2) { 1656 for (var jj in ar2) { 1657 if (ar2.hasOwnProperty(jj)) { 1658 ar1[jj] = main_core.Type.isPlainObject(ar2[jj]) && main_core.Type.isPlainObject(ar1[jj]) ? merge(ar1[jj], ar2[jj]) : ar2[jj]; 1659 } 1660 } 1661 1662 return ar1; 1663 }; 1664 1665 this.response = merge(this.response, data); 1666 1667 if (data.status === 'error') { 1668 this.error('Error in a uploading'); 1669 } else if (!data['files']) { 1670 this.error('Unexpected server response.'); 1671 } else { 1672 this.filesInprogress.forEach(function (itemId) { 1673 var fileResponse = data['files'][itemId] || { 1674 status: 'error', 1675 errors: ['File data is not found'] 1676 }; 1677 1678 if (fileResponse.status === 'error' || fileResponse.status === 'uploaded') { 1679 _this6.filesVirgin.delete(itemId); 1680 1681 _this6.emit(fileResponse.status === 'error' ? 'fileIsErrored' : 'fileIsUploaded', { 1682 itemId: itemId, 1683 item: _this6.files.get(itemId).item, 1684 response: fileResponse 1685 }); 1686 } 1687 1688 _this6.files.get(itemId).parseResponse(fileResponse); 1689 }); 1690 this.filesInprogress.clear(); 1691 } 1692 } 1693 }, { 1694 key: "checkAndDone", 1695 value: function checkAndDone(stream) { 1696 console.log('5. Form has been sent.'); 1697 1698 if (this.response['status'] === 'done') { 1699 this.done(stream); 1700 } else if (this.response['status'] === 'start') { 1701 this.error('Error with starting package.'); 1702 } else if (this.response['status'] !== 'continue') { 1703 this.error('Unknown response'); 1704 } 1705 } 1706 }, { 1707 key: "done", 1708 value: function done(stream) { 1709 console.log('5.1 Release the stream'); 1710 this.unbindStream(stream);
1711 this.emit('done', { 1712 status: this.errors.length <= 0 ? 'success' : 'failed' 1713 }); 1714 } 1715 }, { 1716 key: "error", 1717 value: function error(errorText) { 1718 var _this7 = this; 1719 1720 var handler = function handler(itemId) { 1721 _this7.emit('fileIsErrored', { 1722 itemId: itemId, 1723 item: _this7.files.get(itemId).item, 1724 response: { 1725 error: errorText, 1726 status: 'failed' 1727 }, 1728 serverResponse: Object.assign({}, _this7.response) 1729 }); 1730 }; 1731 1732 this.filesVirgin.forEach(handler); 1733 this.filesVirgin.clear(); 1734 this.filesInprogress.forEach(handler); 1735 this.filesInprogress.clear(); 1736 this.errors.push(errorText); 1737 console.log('5. Form has been sent with errors: ', this.errors); 1738 this.done(this.stream); 1739 } 1740 }, { 1741 key: "getServerResponse", 1742 value: function getServerResponse() { 1743 return this.response; 1744 } 1745 }, { 1746 key: "filesCount", 1747 get: function get() { 1748 return this.filesVirgin.size + this.filesInprogress.size; 1749 } 1750 }, { 1751 key: "data", 1752 get: function get() { 1753 return convertFormDataToObject(this.formData); 1754 } 1755 }]); 1756 return Package; 1757 }(main_core_events.EventEmitter); 1758 1759 function _classStaticPrivateMethodGet(receiver, classConstructor, method) { _classCheckPrivateStaticAccess$1(receiver, classConstructor); return method; } 1760 1761 function _classStaticPrivateFieldSpecGet$1(receiver, classConstructor, descriptor) { _classCheckPrivateStaticAccess$1(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor$1(descriptor, "get"); return _classApplyDescriptorGet$1(receiver, descriptor); } 1762 1763 function _classCheckPrivateStaticFieldDescriptor$1(descriptor, action) { if (descriptor === undefined) { throw new TypeError("attempted to " + action + " private static field before its declaration"); } } 1764 1765 function _classCheckPrivateStaticAccess$1(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } } 1766 1767 function _classApplyDescriptorGet$1(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } 1768 1769 var Streams = /*#__PURE__*/function (_EventEmitter) { 1770 babelHelpers.inherits(Streams, _EventEmitter); 1771 1772 function Streams() { 1773 babelHelpers.classCallCheck(this, Streams); 1774 return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Streams).apply(this, arguments)); 1775 } 1776 1777 babelHelpers.createClass(Streams, null, [{ 1778 key: "addPackage", 1779 value: function addPackage(pack) { 1780 console.log('3. Add to a stream queue.'); 1781 1782 if (this.maxInstances > 0 && _classStaticPrivateFieldSpecGet$1(this, Streams, _instance).size > this.maxInstances) { 1783 _classStaticPrivateFieldSpecGet$1(this, Streams, _packages).set(pack); 1784 } else { 1785 _classStaticPrivateFieldSpecGet$1(this, Streams, _packages).delete(pack); 1786 1787 _classStaticPrivateMethodGet(this, Streams, _runPackage).call(this, pack); 1788 } 1789 1790 if (!window[_classStaticPrivateFieldSpecGet$1(this, Streams, _hiddenTag)]) { 1791 window[_classStaticPrivateFieldSpecGet$1(this, Streams, _hiddenTag)] = _classStaticPrivateMethodGet(this, Streams, _catchWindow).bind(this); 1792 main_core.Event.bind(window, 'beforeunload', window[_classStaticPrivateFieldSpecGet$1(this, Streams, _hiddenTag)]); 1793 } 1794 } 1795 }]); 1796 return Streams; 1797 }(main_core_events.EventEmitter); 1798 1799 function _catchWindow(event) { 1800 if (_classStaticPrivateFieldSpecGet$1(this, Streams, _packages).size > 0 || _classStaticPrivateFieldSpecGet$1(this, Streams, _instance).size > 0) { 1801 var confirmationMessage = main_core.Loc.getMessage('UPLOADER_UPLOADING_ONBEFOREUNLOAD'); 1802 (event || window.event).returnValue = confirmationMessage; 1803 return confirmationMessage; 1804 } 1805 } 1806 1807 function _runPackage(pack) { 1808 var _this = this; 1809 1810 var stream = new Stream(); 1811 1812 _classStaticPrivateFieldSpecGet$1(this, Streams, _instance).set(stream); 1813 1814 console.log('3.1. Run package in a stream.'); 1815 pack.subscribeOnce('done', function () { 1816 console.log('6. Package is done so release the stream.'); 1817 1818 _classStaticPrivateFieldSpecGet$1(_this, Streams, _instance).delete(stream); 1819 1820 stream.destroy(); 1821 1822 if (_classStaticPrivateFieldSpecGet$1(_this, Streams, _packages).size > 0) { 1823 var _classStaticPrivateFi = babelHelpers.slicedToArray(_classStaticPrivateFieldSpecGet$1(_this, Streams, _packages).entries().next().value, 1), 1824 newPack = _classStaticPrivateFi[0]; 1825 1826 _this.addPackage(newPack); 1827 } else if (_classStaticPrivateFieldSpecGet$1(_this, Streams, _instance).size <= 0) { 1828 main_core.Event.unbind(window, 'beforeunload', window[_classStaticPrivateFieldSpecGet$1(_this, Streams, _hiddenTag)]); 1829 delete window[_classStaticPrivateFieldSpecGet$1(_this, Streams, _hiddenTag)]; 1830 } 1831 }); 1832 pack.run(stream); 1833 } 1834 1835 babelHelpers.defineProperty(Streams, "maxInstances", 3); 1836 var _instance = { 1837 writable: true, 1838 value: new Map() 1839 }; 1840 var _packages = { 1841 writable: true, 1842 value: new Map() 1843 }; 1844 var _hiddenTag = { 1845 writable: true, 1846 value: Symbol('streams descriptor') 1847 }; 1848 1849 (function (window) { 1850 window.BX = window['BX'] || {}; 1851 if (window.BX["UploaderQueue"]) return false;
1852 var BX = window.BX, 1853 statuses = { 1854 "new": 0, 1855 ready: 1, 1856 preparing: 2, 1857 inprogress: 3, 1858 done: 4, 1859 failed: 5, 1860 stopped: 6, 1861 changed: 7, 1862 uploaded: 8 1863 }; 1864 /** 1865 * @return {BX.UploaderQueue} 1866 * @params array 1867 * @params[placeHolder] - DOM node to append files /OL or UL/ 1868 */ 1869 1870 BX.UploaderQueue = function (params, limits, caller) { 1871 this.dialogName = "BX.UploaderQueue"; 1872 limits = !!limits ? limits : {}; 1873 this.limits = { 1874 phpPostMaxSize: limits["phpPostMaxSize"], 1875 phpUploadMaxFilesize: limits["phpUploadMaxFilesize"], 1876 uploadMaxFilesize: limits["uploadMaxFilesize"] > 0 ? limits["uploadMaxFilesize"] : 0, 1877 uploadFileWidth: limits["uploadFileWidth"] > 0 ? limits["uploadFileWidth"] : 0, 1878 uploadFileHeight: limits["uploadFileHeight"] > 0 ? limits["uploadFileHeight"] : 0 1879 }; 1880 this.placeHolder = BX(params["placeHolder"]); 1881 this.showImage = params["showImage"] !== false && params["showImage"] !== 'N'; 1882 this.sortItems = params["sortItems"] !== false && params["sortItems"] !== 'N'; 1883 this.fileCopies = params["copies"]; 1884 this.fileFields = params["fields"]; 1885 this.uploader = caller; 1886 this.itForUpload = new BX.UploaderUtils.Hash(); 1887 this.items = new BX.UploaderUtils.Hash(); 1888 this.itUploaded = new BX.UploaderUtils.Hash(); 1889 this.itFailed = new BX.UploaderUtils.Hash(); 1890 this.thumb = { 1891 tagName: "LI", 1892 className: "bx-bxu-thumb-thumb" 1893 }; 1894 1895 if (!!params["thumb"]) { 1896 for (var ii in params["thumb"]) { 1897 if (params["thumb"].hasOwnProperty(ii) && this.thumb.hasOwnProperty(ii)) { 1898 this.thumb[ii] = params["thumb"][ii]; 1899 } 1900 } 1901 } 1902 1903 BX.addCustomEvent(caller, "onItemIsAdded", BX.delegate(this.addItem, this)); 1904 BX.addCustomEvent(caller, "onFileIsDeleted", BX.delegate(this.deleteItem, this)); 1905 BX.addCustomEvent(caller, "onFileIsReinited", BX.delegate(this.reinitItem, this)); 1906 this.log('Initialized'); 1907 return this; 1908 }; 1909 1910 BX.UploaderQueue.prototype = { 1911 showError: function showError(text) { 1912 this.log('Error! ' + text); 1913 }, 1914 log: function log(text) { 1915 BX.UploaderUtils.log('queue', text); 1916 }, 1917 addItem: function addItem(file, being) { 1918 var isImage; 1919 if (!this.showImage) isImage = false;else if (BX.type.isDomNode(file)) isImage = BX.UploaderUtils.isImage(file.value, null, null);else isImage = BX.UploaderUtils.isImage(file["name"], file["type"], file["size"]); 1920 BX.onCustomEvent(this.uploader, "onFileIsBeforeCreated", [file, being, isImage, this.uploader]); 1921 var params = { 1922 copies: this.fileCopies, 1923 fields: this.fileFields 1924 }, 1925 res = isImage ? new BX.UploaderImage(file, params, this.limits, this.uploader) : new BX.UploaderFile(file, params, this.limits, this.uploader), 1926 children, 1927 node, 1928 itemStatus = { 1929 status: statuses.ready 1930 }; 1931 BX.onCustomEvent(res, "onFileIsAfterCreated", [res, being, itemStatus, this.uploader]); 1932 BX.onCustomEvent(this.uploader, "onFileIsAfterCreated", [res, being, itemStatus, this.uploader]); 1933 this.items.setItem(res.id, res); 1934 1935 if (being || itemStatus["status"] !== statuses.ready) { 1936 this.itUploaded.setItem(res.id, res); 1937 } else { 1938 this.itForUpload.setItem(res.id, res); 1939 } 1940 1941 if (!!this.placeHolder) { 1942 if (BX(being)) { 1943 res.thumbNode = node = BX(being); 1944 node.setAttribute("bx-bxu-item-id", res.id); 1945 } else { 1946 children = res.makeThumb(); 1947 node = BX.create(this.thumb.tagName, { 1948 attrs: { 1949 id: res.id + 'Item', 1950 'bx-bxu-item-id': res.id, 1951 className: this.thumb.className 1952 } 1953 }); 1954 1955 if (BX.type.isNotEmptyString(children)) { 1956 if (this.thumb.tagName == 'TR') { 1957 children = children.replace(/[\n\t]/gi, "").replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1"); 1958 if (!!children["trim"]) children = children.trim(); 1959 1960 var replaceFunction = function replaceFunction(str, tdParams, tdInnerHTML) { 1961 var td = node.insertCell(-1), 1962 attrs = { 1963 colspan: true, 1964 headers: true, 1965 accesskey: true, 1966 "class": true, 1967 contenteditable: true, 1968 contextmenu: true, 1969 dir: true, 1970 hidden: true, 1971 id: true, 1972 lang: true, 1973 spellcheck: true, 1974 style: true, 1975 tabindex: true, 1976 title: true, 1977 translate: true 1978 }, 1979 param; 1980 td.innerHTML = tdInnerHTML; 1981 tdParams = tdParams.split(" "); 1982 1983 while ((param = tdParams.pop()) && param) { 1984 param = param.split("="); 1985 1986 if (param.length == 2) { 1987 param[0] = param[0].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1"); 1988 param[1] = param[1].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1"); 1989 if (attrs[param[0]] === true) td.setAttribute(param[0], param[1]);else td[param[0]] = param[1]; 1990 } 1991 } 1992 1993 return ""; 1994 }, 1995 regex = /^<td(.*?)>(.*?)<\/td>/i; 1996 1997 window.data1 = children; 1998 1999 while (regex.test(children)) { 2000 children = children.replace(regex, replaceFunction); 2001 } 2002 } else { 2003 node.innerHTML = children; 2004 } 2005 } else if (BX.type.isDomNode(children)) { 2006 BX.adjust(node, { 2007 children: [children] 2008 }); 2009 } 2010 } 2011 2012 if (!!window["jsDD"] && this.sortItems) { 2013 if (!this._onbxdragstart) { 2014 this._onbxdragstart = BX.delegate(this.onbxdragstart, this); 2015 this._onbxdragstop = BX.delegate(this.onbxdragstop, this); 2016 this._onbxdrag = BX.delegate(this.onbxdrag, this); 2017 this._onbxdraghout = BX.delegate(this.onbxdraghout, this); 2018 this._onbxdestdraghover = BX.delegate(this.onbxdestdraghover, this); 2019 this._onbxdestdraghout = BX.delegate(this.onbxdestdraghout, this); 2020 this._onbxdestdragfinish = BX.delegate(this.onbxdestdragfinish, this); 2021 } 2022 2023 BX.addClass(node, "bx-drag-draggable"); 2024 node.onbxdragstart = this._onbxdragstart; 2025 node.onbxdragstop = this._onbxdragstop; 2026 node.onbxdrag = this._onbxdrag; 2027 node.onbxdraghout = this._onbxdraghout; 2028 window.jsDD.registerObject(node); 2029 node.onbxdestdraghover = this._onbxdestdraghover; 2030 node.onbxdestdraghout = this._onbxdestdraghout; 2031 node.onbxdestdragfinish = this._onbxdestdragfinish; 2032 window.jsDD.registerDest(node); 2033 var inputs = BX.findChild(node, { 2034 tagName: "INPUT", 2035 props: { 2036 "type": "text" 2037 } 2038 }, true, true); 2039 2040 for (var ii = 0; ii <= inputs.length; ii++) { 2041 BX.bind(inputs[ii], "mousedown", BX.eventCancelBubble); 2042 } 2043 } 2044 2045 node.setAttribute("bx-item-id", res.id); 2046 2047 if (BX(being)) { 2048 BX.onCustomEvent(this.uploader, "onFileIsBound", [res.id, res, this.caller, being]); 2049 BX.onCustomEvent(res, "onFileIsBound", [res.id, res, this.caller, being]); 2050 } else if (!!being) { 2051 this.placeHolder.appendChild(node); 2052 BX.onCustomEvent(this.uploader, "onFileIsAttached", [res.id, res, this.caller, being]); 2053 BX.onCustomEvent(res, "onFileIsAttached", [res.id, res, this.caller, being]); 2054 } else { 2055 this.placeHolder.appendChild(node); 2056 BX.onCustomEvent(this.uploader, "onFileIsAppended", [res.id, res, this.caller]); 2057 BX.onCustomEvent(res, "onFileIsAppended", [res.id, res, this.caller]); 2058 } 2059 } 2060 2061 BX.onCustomEvent(this.uploader, "onQueueIsChanged", [this, "add", res.id, res]); 2062 }, 2063 getItem: function getItem(id) { 2064 var item = this.items.getItem(id); 2065 if (item) return { 2066 item: item, 2067 node: item.thumbNode || BX(id + 'Item') 2068 }; 2069 return null; 2070 }, 2071 onbxdragstart: function onbxdragstart() { 2072 var item = BX.proxy_context, 2073 id = item && item.getAttribute("bx-item-id"); 2074 2075 if (id) { 2076 var template = item.innerHTML.replace(new RegExp(id, "gi"), "DragCopy"); 2077 item.__dragCopyDiv = BX.create('DIV', { 2078 attrs: { 2079 className: "bx-drag-object " + item.className 2080 }, 2081 style: { 2082 position: "absolute", 2083 zIndex: 10, 2084 width: item.clientWidth + 'px' 2085 }, 2086 html: template 2087 }); 2088 item.__dragCopyPos = BX.pos(item); 2089 BX.onCustomEvent(this.uploader, "onBxDragStart", [item, item.__dragCopyDiv]); 2090 document.body.appendChild(item.__dragCopyDiv); 2091 BX.addClass(item, "bx-drag-source"); 2092 var c = BX('DragCopyProperCanvas'),
2093 c1, 2094 it = this.items.getItem(id); 2095 2096 if (c && it && BX(it.canvas)) { 2097 c1 = it.canvas.cloneNode(true); 2098 c.parentNode.replaceChild(c1, c); 2099 c1.getContext("2d").drawImage(it.canvas, 0, 0); 2100 } 2101 } 2102 2103 return true; 2104 }, 2105 onbxdragstop: function onbxdragstop() { 2106 var item = BX.proxy_context; 2107 2108 if (item.__dragCopyDiv) { 2109 BX.removeClass(item, "bx-drag-source"); 2110 2111 item.__dragCopyDiv.parentNode.removeChild(item.__dragCopyDiv); 2112 2113 item.__dragCopyDiv = null; 2114 delete item['__dragCopyDiv']; 2115 delete item['__dragCopyPos']; 2116 } 2117 2118 return true; 2119 }, 2120 onbxdrag: function onbxdrag(x, y) { 2121 var item = BX.proxy_context, 2122 div = item.__dragCopyDiv; 2123 2124 if (div) { 2125 if (item.__dragCopyPos) { 2126 if (!item.__dragCopyPos.deltaX) item.__dragCopyPos.deltaX = item.__dragCopyPos.left - x; 2127 if (!item.__dragCopyPos.deltaY) item.__dragCopyPos.deltaY = item.__dragCopyPos.top - y; 2128 x += item.__dragCopyPos.deltaX; 2129 y += item.__dragCopyPos.deltaY; 2130 } 2131 2132 div.style.left = x + 'px'; 2133 div.style.top = y + 'px'; 2134 } 2135 }, 2136 onbxdraghout: function onbxdraghout(currentNode, x, y) {}, 2137 onbxdestdraghover: function onbxdestdraghover(currentNode) { 2138 if (!currentNode || !currentNode.hasAttribute("bx-bxu-item-id") || !this.items.hasItem(currentNode.getAttribute("bx-bxu-item-id"))) return; 2139 var item = BX.proxy_context; 2140 BX.addClass(item, "bx-drag-over"); 2141 return true; 2142 }, 2143 onbxdestdraghout: function onbxdestdraghout() { 2144 var item = BX.proxy_context; 2145 BX.removeClass(item, "bx-drag-over"); 2146 return true; 2147 }, 2148 onbxdestdragfinish: function onbxdestdragfinish(currentNode) { 2149 var item = BX.proxy_context; 2150 BX.removeClass(item, "bx-drag-over"); 2151 if (item == currentNode || !BX.hasClass(currentNode, "bx-drag-draggable")) return true; 2152 var id = currentNode.getAttribute("bx-bxu-item-id"); 2153 if (!this.items.hasItem(id)) return; 2154 var obj = item.parentNode, 2155 n = obj.childNodes.length, 2156 act, 2157 it, 2158 buff, 2159 j; 2160 2161 for (j = 0; j < n; j++) { 2162 if (obj.childNodes[j] == item) item.number = j;else if (obj.childNodes[j] == currentNode) currentNode.number = j; 2163 if (currentNode.number > 0 && item.number > 0) break; 2164 } 2165 2166 if (this.itForUpload.hasItem(id)) { 2167 act = item.number <= currentNode.number ? "beforeItem" : item.nextSibling ? "afterItem" : "inTheEnd"; 2168 it = null; 2169 2170 if (act != "inTheEnd") { 2171 for (j = item.number + (act == "beforeItem" ? 0 : 1); j < n; j++) { 2172 if (this.itForUpload.hasItem(obj.childNodes[j].getAttribute("bx-bxu-item-id"))) { 2173 it = obj.childNodes[j].getAttribute("bx-bxu-item-id"); 2174 break; 2175 } 2176 } 2177 2178 if (it === null) act = "inTheEnd"; 2179 } 2180 2181 buff = this.itForUpload.removeItem(currentNode.getAttribute("bx-bxu-item-id")); 2182 if (act != "inTheEnd") this.itForUpload.insertBeforeItem(buff.id, buff, it);else this.itForUpload.setItem(buff.id, buff); 2183 } 2184 2185 act = item.number <= currentNode.number ? "beforeItem" : item.nextSibling ? "afterItem" : "inTheEnd"; 2186 it = null; 2187 2188 if (act != "inTheEnd") { 2189 for (j = item.number + (act == "beforeItem" ? 0 : 1); j < n; j++) { 2190 if (this.items.hasItem(obj.childNodes[j].getAttribute("bx-bxu-item-id"))) { 2191 it = obj.childNodes[j].getAttribute("bx-bxu-item-id"); 2192 break; 2193 } 2194 } 2195 2196 if (it === null) act = "inTheEnd"; 2197 } 2198 2199 buff = this.items.removeItem(currentNode.getAttribute("bx-bxu-item-id")); 2200 if (act != "inTheEnd") this.items.insertBeforeItem(buff.id, buff, it);else this.items.setItem(buff.id, buff); 2201 currentNode.parentNode.removeChild(currentNode); 2202 2203 if (item.number <= currentNode.number) { 2204 item.parentNode.insertBefore(currentNode, item); 2205 } else if (item.nextSibling) { 2206 item.parentNode.insertBefore(currentNode, item.nextSibling); 2207 } else { 2208 for (j = 0; j < n; j++) { 2209 if (obj.childNodes[j] == item) item.number = j;else if (obj.childNodes[j] == currentNode) currentNode.number = j; 2210 } 2211 2212 if (item.number <= currentNode.number) { 2213 item.parentNode.insertBefore(currentNode, item); 2214 } else { 2215 item.parentNode.appendChild(currentNode); 2216 } 2217 } 2218 2219 BX.onCustomEvent(item, "onFileOrderIsChanged", [item.id, item, this.caller]); 2220 BX.onCustomEvent(this.uploader, "onQueueIsChanged", [this, "sort", item.id, item]); 2221 return true; 2222 }, 2223 deleteItem: function deleteItem(id, item) { 2224 var pointer = this.getItem(id), 2225 node; 2226 2227 if (pointer && (!this.placeHolder || (node = pointer.node) && node)) { 2228 if (!!node) { 2229 if (!!window["jsDD"]) { 2230 node.onmousedown = null; 2231 node.onbxdragstart = null; 2232 node.onbxdragstop = null; 2233 node.onbxdrag = null; 2234 node.onbxdraghout = null; 2235 node.onbxdestdraghover = null; 2236 node.onbxdestdraghout = null; 2237 node.onbxdestdragfinish = null; 2238 node.__bxpos = null; 2239 window.jsDD.arObjects[node.__bxddid] = null; 2240 delete window.jsDD.arObjects[node.__bxddid]; 2241 window.jsDD.arDestinations[node.__bxddeid] = null; 2242 delete window.jsDD.arDestinations[node.__bxddeid]; 2243 } 2244 2245 BX.unbindAll(node); 2246 if (item["replaced"] !== true) node.parentNode.removeChild(node); 2247 } 2248 2249 this.items.removeItem(id); 2250 this.itUploaded.removeItem(id); 2251 this.itFailed.removeItem(id); 2252 this.itForUpload.removeItem(id); 2253 BX.onCustomEvent(this.uploader, "onQueueIsChanged", [this, "delete", id, item]); 2254 return true; 2255 } 2256 2257 return false;
2258 }, 2259 reinitItem: function reinitItem(id, item) { 2260 var node, children; 2261 2262 if (!!this.placeHolder && this.items.hasItem(id) && (node = BX(id + 'Item')) && node) { 2263 children = item.makeThumb(); 2264 2265 if (BX.type.isNotEmptyString(children)) { 2266 if (this.thumb.tagName == 'TR') { 2267 children = children.replace(/[\n\t]/gi, "").replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1"); 2268 if (!!children["trim"]) children = children.trim(); 2269 2270 var replaceFunction = function replaceFunction(str, tdParams, tdInnerHTML) { 2271 var td = node.insertCell(-1), 2272 attrs = { 2273 colspan: true, 2274 headers: true, 2275 accesskey: true, 2276 "class": true, 2277 contenteditable: true, 2278 contextmenu: true, 2279 dir: true, 2280 hidden: true, 2281 id: true, 2282 lang: true, 2283 spellcheck: true, 2284 style: true, 2285 tabindex: true, 2286 title: true, 2287 translate: true 2288 }, 2289 param; 2290 td.innerHTML = tdInnerHTML; 2291 tdParams = tdParams.split(" "); 2292 2293 while ((param = tdParams.pop()) && param) { 2294 param = param.split("="); 2295 2296 if (param.length == 2) { 2297 param[0] = param[0].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1"); 2298 param[1] = param[1].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1"); 2299 if (attrs[param[0]] === true) td.setAttribute(param[0], param[1]);else td[param[0]] = param[1]; 2300 } 2301 } 2302 2303 return ""; 2304 }, 2305 regex = /^<td(.*?)>(.*?)<\/td>/i; 2306 2307 window.data1 = children; 2308 2309 while (regex.test(children)) { 2310 children = children.replace(regex, replaceFunction); 2311 } 2312 } else { 2313 node.innerHTML = children; 2314 } 2315 } else if (BX.type.isDomNode(children)) { 2316 while (BX(node.firstChild)) { 2317 BX.remove(node.firstChild); 2318 } 2319 2320 BX.adjust(node, { 2321 children: [children] 2322 }); 2323 } 2324 2325 BX.onCustomEvent(this.uploader, "onFileIsAppended", [item.id, item, this.caller]); 2326 BX.onCustomEvent(item, "onFileIsAppended", [item.id, item, this.caller]); 2327 } 2328 }, 2329 clear: function clear() { 2330 var item; 2331 2332 while ((item = this.items.getFirst()) && !!item) { 2333 this.deleteItem(item.id, item); 2334 } 2335 }, 2336 restoreFiles: function restoreFiles(data, restoreErrored, startAgain) { 2337 data.reset(); 2338 var item, copy, erroredFile; 2339 2340 while ((item = data.getNext()) && item) { 2341 erroredFile = this.itFailed.hasItem(item.id); 2342 2343 if (restoreErrored === true) { 2344 this.itFailed.removeItem(item.id); 2345 } 2346 2347 if (!this.items.hasItem(item.id) || this.itFailed.hasItem(item.id)) { 2348 continue; 2349 } 2350 2351 if (startAgain === true || startAgain !== false && erroredFile) // for compatibility 2352 { 2353 delete item["uploadStatus"]; 2354 delete item.file["uploadStatus"]; 2355 delete item.file["firstChunk"]; 2356 delete item.file["package"]; 2357 delete item.file["packages"]; 2358 2359 if (item.file["copies"]) { 2360 item.file["copies"].reset(); 2361 2362 while ((copy = item.file["copies"].getNext()) && copy) { 2363 delete copy["uploadStatus"]; 2364 delete copy["firstChunk"]; 2365 delete copy["package"]; 2366 delete copy["packages"]; 2367 } 2368 2369 item.file["copies"].reset(); 2370 } 2371 2372 item["restored"] = startAgain === true ? "Y" : "C"; // Start again or continue 2373 } else { 2374 if (erroredFile) // If a error was occurred on the last step we should send this piece again 2375 { 2376 if (item.file["package"]) { 2377 item.file["package"]--; 2378 } 2379 2380 if (item.file["copies"]) { 2381 item.file["copies"].reset(); 2382 2383 while ((copy = item.file["copies"].getNext()) && copy) { 2384 delete copy["uploadStatus"]; 2385 delete copy["firstChunk"]; 2386 delete copy["package"]; 2387 delete copy["packages"]; 2388 } 2389 2390 item.file["copies"].reset(); 2391 } 2392 } 2393 2394 item["restored"] = "C"; // Continue 2395 } 2396 2397 this.itUploaded.removeItem(item.id); 2398 this.itForUpload.setItem(item.id, item); 2399 BX.onCustomEvent(item, "onUploadRestore", [item]); 2400 } 2401 } 2402 }; 2403 return statuses; 2404 })(window); 2405 2406 (function (window) { 2407 window.BX = window['BX'] || {}; 2408 if (window.BX["UploaderUtils"]) return false;
2409 var BX = window.BX; 2410 BX.UploaderLog = []; 2411 BX.UploaderDebug = false; 2412 var statuses = { 2413 "new": 0, 2414 ready: 1, 2415 preparing: 2, 2416 inprogress: 3, 2417 done: 4, 2418 failed: 5, 2419 stopped: 6, 2420 changed: 7, 2421 uploaded: 8 2422 }; 2423 BX.UploaderUtils = { 2424 statuses: statuses, 2425 getId: function getId() { 2426 return new Date().valueOf() + Math.round(Math.random() * 1000000); 2427 }, 2428 log: function log() { 2429 if (BX.UploaderDebug === true) { 2430 console.log(arguments); 2431 } else { 2432 BX.UploaderLog.push(arguments); 2433 } 2434 }, 2435 Hash: function () { 2436 var d = function d() { 2437 this.length = 0; 2438 this.items = {}; 2439 this.order = []; 2440 var i; 2441 2442 if (arguments.length == 1 && BX.type.isArray(arguments[0]) && arguments[0].length > 0) { 2443 var data = arguments[0]; 2444 2445 for (i = 0; i < data.length; i++) { 2446 if (data[i] && babelHelpers.typeof(data[i]) == "object" && data[i]["id"]) { 2447 this.setItem(data[i]["id"], data[i]); 2448 } 2449 } 2450 } else { 2451 for (i = 0; i < arguments.length; i += 2) { 2452 this.setItem(arguments[i], arguments[i + 1]); 2453 } 2454 } 2455 }; 2456 2457 d.prototype = { 2458 getIds: function getIds() { 2459 return this.order; 2460 }, 2461 getQueue: function getQueue(id) { 2462 id += ''; 2463 return BX.util.array_search(id, this.order); 2464 }, 2465 getByOrder: function getByOrder(order) { 2466 return this.getItem(this.order[order]); 2467 }, 2468 removeItem: function removeItem(in_key) { 2469 in_key += ''; 2470 var tmp_value, number; 2471 2472 if (typeof this.items[in_key] != 'undefined') { 2473 tmp_value = this.items[in_key]; 2474 number = this.getQueue(in_key); 2475 this.pointer -= this.pointer >= number ? 1 : 0; 2476 delete this.items[in_key]; 2477 this.order = BX.util.deleteFromArray(this.order, number); 2478 this.length = this.order.length; 2479 } 2480 2481 return tmp_value; 2482 }, 2483 getItem: function getItem(in_key) { 2484 in_key += ''; 2485 return this.items[in_key]; 2486 }, 2487 unshiftItem: function unshiftItem(in_key, in_value) { 2488 in_key += ''; 2489 2490 if (typeof in_value != 'undefined') { 2491 if (typeof this.items[in_key] == 'undefined') { 2492 this.order.unshift(in_key); 2493 this.length = this.order.length; 2494 } 2495 2496 this.items[in_key] = in_value; 2497 } 2498 2499 return in_value; 2500 }, 2501 setItem: function setItem(in_key, in_value) { 2502 in_key += ''; 2503 2504 if (typeof in_value != 'undefined') { 2505 if (typeof this.items[in_key] == 'undefined') { 2506 this.order.push(in_key); 2507 this.length = this.order.length; 2508 } 2509 2510 this.items[in_key] = in_value; 2511 } 2512 2513 return in_value; 2514 }, 2515 hasItem: function hasItem(in_key) { 2516 in_key += ''; 2517 return typeof this.items[in_key] != 'undefined'; 2518 }, 2519 insertBeforeItem: function insertBeforeItem(in_key, in_value, after_key) { 2520 in_key += ''; 2521 2522 if (typeof in_value != 'undefined') { 2523 if (typeof this.items[in_key] == 'undefined') { 2524 this.order.splice(this.getQueue(after_key), 0, in_key); 2525 this.length = this.order.length; 2526 } 2527 2528 this.items[in_key] = in_value; 2529 } 2530 2531 return in_value; 2532 }, 2533 getFirst: function getFirst() { 2534 var in_key, 2535 item = null; 2536 2537 for (var ii = 0; ii < this.order.length; ii++) { 2538 in_key = this.order[ii]; 2539 2540 if (!!in_key && this.hasItem(in_key)) { 2541 item = this.getItem(in_key); 2542 break; 2543 } 2544 } 2545 2546 return item; 2547 }, 2548 getNext: function getNext() { 2549 this.pointer = 0 <= this.pointer && this.pointer < this.order.length ? this.pointer : -1; 2550 var res = this.getItem(this.order[this.pointer + 1]); 2551 if (!!res) this.pointer++;else this.pointer = -1; 2552 return res; 2553 }, 2554 getPrev: function getPrev() { 2555 this.pointer = 0 <= this.pointer && this.pointer < this.order.length ? this.pointer : 0; 2556 var res = this.getItem(this.order[this.pointer - 1]); 2557 if (!!res) this.pointer--; 2558 return res; 2559 }, 2560 reset: function reset() { 2561 this.pointer = -1; 2562 }, 2563 setPointer: function setPointer(in_key) { 2564 this.pointer = this.getQueue(in_key); 2565 return this.pointer; 2566 }, 2567 getLast: function getLast() { 2568 var in_key, 2569 item = null; 2570 2571 for (var ii = this.order.length; ii >= 0; ii--) { 2572 in_key = this.order[ii]; 2573 2574 if (!!in_key && this.hasItem(in_key)) { 2575 item = this.getItem(in_key); 2576 break; 2577 } 2578 } 2579 2580 return item; 2581 } 2582 }; 2583 return d; 2584 }(), 2585 getFileNameOnly: function getFileNameOnly(name) { 2586 var delimiter = "\\", 2587 start = name.lastIndexOf(delimiter), 2588 finish = name.length; 2589 2590 if (start == -1) { 2591 delimiter = "/"; 2592 start = name.lastIndexOf(delimiter); 2593 } 2594 2595 if (start + 1 == name.length) { 2596 finish = start; 2597 start = name.substring(0, finish).lastIndexOf(delimiter); 2598 } 2599 2600 name = name.substring(start + 1, finish); 2601 2602 if (delimiter == "/" && name.indexOf("?") > 0) { 2603 name = name.substring(0, name.indexOf("?")); 2604 } 2605 2606 if (name == '') name = 'noname'; 2607 return name; 2608 }, 2609 isImageExt: function isImageExt(ext) { 2610 return BX.message('bxImageExtensions') && BX.type.isNotEmptyString(ext) ? new RegExp('(?:^|\\W)(' + ext + ')(?:\\W|$)', 'gi').test(BX.message('bxImageExtensions')) : false;
2611 }, 2612 isImage: function isImage(name, type, size) { 2613 size = BX.type.isNumber(size) ? size : BX.type.isNotEmptyString(size) && !/[\D]+/gi.test(size) ? parseInt(size) : null; 2614 return (type === null || (type || '').indexOf("image/") === 0) && (size === null || size < 20 * 1024 * 1024) && BX.UploaderUtils.isImageExt((name || '').lastIndexOf('.') > 0 ? name.substr(name.lastIndexOf('.') + 1).toLowerCase() : ''); 2615 }, 2616 scaleImage: function scaleImage(arSourceSize, arSize, resizeType) { 2617 var sourceImageWidth = parseInt(arSourceSize["width"]), 2618 sourceImageHeight = parseInt(arSourceSize["height"]); 2619 resizeType = !resizeType && !!arSize["type"] ? arSize["type"] : resizeType; 2620 arSize = !!arSize ? arSize : {}; 2621 arSize.width = parseInt(!!arSize.width ? arSize.width : 0); 2622 arSize.height = parseInt(!!arSize.height ? arSize.height : 0); 2623 var res = { 2624 bNeedCreatePicture: false, 2625 source: { 2626 x: 0, 2627 y: 0, 2628 width: 0, 2629 height: 0 2630 }, 2631 destin: { 2632 x: 0, 2633 y: 0, 2634 width: 0, 2635 height: 0 2636 } 2637 }, 2638 width, 2639 height; 2640 2641 if (!(sourceImageWidth > 0 || sourceImageHeight > 0)) { 2642 BX.DoNothing(); 2643 } else { 2644 if (!BX.type.isNotEmptyString(resizeType)) { 2645 resizeType = "inscribed"; 2646 } 2647 2648 var ResizeCoeff, iResizeCoeff; 2649 2650 if (resizeType.indexOf("proportional") >= 0) { 2651 width = Math.max(sourceImageWidth, sourceImageHeight); 2652 height = Math.min(sourceImageWidth, sourceImageHeight); 2653 } else { 2654 width = sourceImageWidth; 2655 height = sourceImageHeight; 2656 } 2657 2658 if (resizeType == "exact") { 2659 var ratio = sourceImageWidth / sourceImageHeight < arSize["width"] / arSize["height"] ? arSize["width"] / sourceImageWidth : arSize["height"] / sourceImageHeight, 2660 x = Math.max(0, Math.round(sourceImageWidth / 2 - arSize["width"] / 2 / ratio)), 2661 y = Math.max(0, Math.round(sourceImageHeight / 2 - arSize["height"] / 2 / ratio)); 2662 res.bNeedCreatePicture = true; 2663 res.coeff = ratio; 2664 res.destin["width"] = arSize["width"]; 2665 res.destin["height"] = arSize["height"]; 2666 res.source["x"] = x; 2667 res.source["y"] = y; 2668 res.source["width"] = Math.round(arSize["width"] / ratio, 0); 2669 res.source["height"] = Math.round(arSize["height"] / ratio, 0); 2670 } else { 2671 if (resizeType == "circumscribed") { 2672 ResizeCoeff = { 2673 width: width > 0 ? arSize["width"] / width : 1, 2674 height: height > 0 ? arSize["height"] / height : 1 2675 }; 2676 iResizeCoeff = Math.max(ResizeCoeff["width"], ResizeCoeff["height"], 1); 2677 } else { 2678 ResizeCoeff = { 2679 width: width > 0 ? arSize["width"] / width : 1, 2680 height: height > 0 ? arSize["height"] / height : 1 2681 }; 2682 iResizeCoeff = Math.min(ResizeCoeff["width"], ResizeCoeff["height"], 1); 2683 iResizeCoeff = 0 < iResizeCoeff ? iResizeCoeff : 1; 2684 } 2685 2686 res.bNeedCreatePicture = iResizeCoeff != 1; 2687 res.coeff = iResizeCoeff; 2688 res.destin["width"] = Math.max(1, parseInt(iResizeCoeff * sourceImageWidth)); 2689 res.destin["height"] = Math.max(1, parseInt(iResizeCoeff * sourceImageHeight)); 2690 res.source["x"] = 0; 2691 res.source["y"] = 0; 2692 res.source["width"] = sourceImageWidth; 2693 res.source["height"] = sourceImageHeight; 2694 } 2695 } 2696 2697 return res; 2698 }, 2699 dataURLToBlob: function dataURLToBlob(dataURL) { 2700 var marker = ';base64,', 2701 parts, 2702 contentType, 2703 raw, 2704 rawLength; 2705 2706 if (dataURL.indexOf(marker) == -1) { 2707 parts = dataURL.split(','); 2708 contentType = parts[0].split(':')[1]; 2709 raw = parts[1]; 2710 return new Blob([raw], { 2711 type: contentType 2712 }); 2713 } 2714 2715 parts = dataURL.split(marker); 2716 contentType = parts[0].split(':')[1]; 2717 raw = window.atob(parts[1]); 2718 rawLength = raw.length; 2719 var uInt8Array = new Uint8Array(rawLength); 2720 2721 for (var i = 0; i < rawLength; ++i) { 2722 uInt8Array[i] = raw.charCodeAt(i); 2723 } 2724 2725 return new Blob([uInt8Array], { 2726 type: contentType 2727 }); 2728 }, 2729 sizeof: function sizeof(obj) { 2730 var size = 0, 2731 key; 2732 2733 for (key in obj) { 2734 if (obj.hasOwnProperty(key)) { 2735 size += key.length; 2736 2737 if (babelHelpers.typeof(obj[key]) == "object") { 2738 if (obj[key] === null) BX.DoNothing();else if (obj[key]["size"] > 0) size += obj[key].size;else size += BX.UploaderUtils.sizeof(obj[key]); 2739 } else if (typeof obj[key] == "number") { 2740 size += obj[key].toString().length; 2741 } else if (!!obj[key] && obj[key].length > 0) { 2742 size += obj[key].length; 2743 } 2744 } 2745 } 2746 2747 return size; 2748 }, 2749 FormToArray: function FormToArray(form, data) {
2750 return BX.ajax.prepareForm(form, data); 2751 }, 2752 getFormattedSize: function getFormattedSize(size, precision) { 2753 var a = ["b", "Kb", "Mb", "Gb", "Tb"], 2754 pos = 0; 2755 2756 while (size >= 1024 && pos < 4) { 2757 size /= 1024; 2758 pos++; 2759 } 2760 2761 return Math.round(size * (precision > 0 ? precision * 10 : 1)) / (precision > 0 ? precision * 10 : 1) + " " + BX.message("FILE_SIZE_" + a[pos]); 2762 }, 2763 bindEvents: function bindEvents(obj, event, func) { 2764 var funcs = [], 2765 ii; 2766 2767 if (typeof func == "string") { 2768 eval('funcs.push(' + func + ');'); 2769 } else if (!!func["length"] && func["length"] > 0) { 2770 for (ii = 0; ii < func.length; ii++) { 2771 if (typeof func[ii] == "string") eval('funcs.push(' + func[ii] + ');');else funcs.push(func[ii]); 2772 } 2773 } else funcs.push(func); 2774 2775 if (funcs.length > 0) { 2776 for (ii = 0; ii < funcs.length; ii++) { 2777 BX.addCustomEvent(obj, event, funcs[ii]); 2778 } 2779 } 2780 }, 2781 applyFilePart: function applyFilePart(file, blob) { 2782 if (BX.type.isDomNode(file)) { 2783 file.uploadStatus = statuses.done; 2784 } else if (file == blob) { 2785 file.uploadStatus = statuses.done; 2786 } else if (file.blobed === true) { 2787 file.uploadStatus = file.package + 1 >= file.packages ? statuses.done : statuses.inprogress; 2788 if (file.uploadStatus == statuses.inprogress) file.package++; 2789 } 2790 2791 return true; 2792 }, 2793 getFilePart: function getFilePart(file, MaxFilesize) { 2794 var blob, 2795 chunkSize = MaxFilesize, 2796 start, 2797 end; 2798 2799 if (BX.type.isDomNode(file)) { 2800 blob = file; 2801 } else if (MaxFilesize <= 0 || file.size <= MaxFilesize) { 2802 blob = file; 2803 } else if (file['packages'] && file['packages'] <= file['package']) { 2804 blob = null; 2805 } else if (window.Blob || window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder) { 2806 if (file['packages']) { 2807 file.package++; 2808 start = file.package * chunkSize; 2809 end = start + chunkSize; 2810 } else { 2811 file.packages = Math.ceil(file.size / chunkSize); 2812 file.package = 0; 2813 start = 0; 2814 end = chunkSize; 2815 } 2816 2817 if ('mozSlice' in file) blob = file.mozSlice(start, end, file.type);else if ('webkitSlice' in file) blob = file.webkitSlice(start, end, file.type);else if ('slice' in file) blob = file.slice(start, end, file.type);else blob = file.Slice(start, end, file.type); 2818 2819 for (var ii in file) { 2820 if (file.hasOwnProperty(ii)) { 2821 blob[ii] = file[ii]; 2822 } 2823 } 2824 2825 blob["name"] = file["name"]; 2826 blob["start"] = start; 2827 blob["package"] = file.package; 2828 blob["packages"] = file.packages; 2829 } 2830 2831 return blob; 2832 }, 2833 makeAnArray: function makeAnArray(file, data) { 2834 file = !!file ? file : { 2835 files: [], 2836 props: {} 2837 }; 2838 var ii; 2839 2840 for (var jj in data) { 2841 if (data.hasOwnProperty(jj)) { 2842 if (babelHelpers.typeof(data[jj]) == "object" && data[jj].length > 0) { 2843 file[jj] = !!file[jj] ? file[jj] : []; 2844 2845 for (ii = 0; ii < data[jj].length; ii++) { 2846 file[jj].push(data[jj][ii]); 2847 } 2848 } else { 2849 for (ii in data[jj]) { 2850 if (data[jj].hasOwnProperty(ii)) { 2851 file[jj] = !!file[jj] ? file[jj] : {}; 2852 file[jj][ii] = data[jj][ii]; 2853 } 2854 } 2855 } 2856 } 2857 } 2858 2859 return file; 2860 }, 2861 appendToForm: function appendToForm(fd, key, val) { 2862 if (!!val && babelHelpers.typeof(val) == "object") { 2863 for (var ii in val) { 2864 if (val.hasOwnProperty(ii)) { 2865 BX.UploaderUtils.appendToForm(fd, key + '[' + ii + ']', val[ii]); 2866 } 2867 } 2868 } else { 2869 fd.append(key, !!val ? val : ''); 2870 } 2871 }, 2872 FormData: function FormData() { 2873 return new (BX.Uploader.getInstanceName() == "BX.UploaderSimple" ? FormDataLocal : window.FormData)(); 2874 }, 2875 prepareData: function prepareData(arData) { 2876 var data = {}; 2877 2878 if (null != arData) { 2879 if (babelHelpers.typeof(arData) == 'object') { 2880 for (var i in arData) { 2881 if (arData.hasOwnProperty(i)) { 2882 var name = BX.util.urlencode(i); 2883 if (babelHelpers.typeof(arData[i]) == 'object') data[name] = BX.UploaderUtils.prepareData(arData[i]);else data[name] = BX.util.urlencode(arData[i]); 2884 } 2885 } 2886 } else data = BX.util.urlencode(arData); 2887 } 2888 2889 return data; 2890 } 2891 }; 2892 2893 var FormDataLocal = function FormDataLocal() { 2894 var uniqueID; 2895 2896 do { 2897 uniqueID = Math.floor(Math.random() * 99999); 2898 } while (BX("form-" + uniqueID)); 2899 2900 this.local = true; 2901 this.form = BX.create("FORM", { 2902 props: { 2903 id: "form-" + uniqueID, 2904 method: "POST", 2905 enctype: "multipart/form-data", 2906 encoding: "multipart/form-data" 2907 }, 2908 style: { 2909 display: "none" 2910 } 2911 }); 2912 document.body.appendChild(this.form); 2913 }; 2914 2915 FormDataLocal.prototype = { 2916 append: function append(name, val) { 2917 if (BX.type.isDomNode(val)) { 2918 this.form.appendChild(val); 2919 } else { 2920 this.form.appendChild(BX.create("INPUT", { 2921 props: { 2922 type: "hidden", 2923 name: name, 2924 value: val 2925 } 2926 })); 2927 } 2928 } 2929 }; 2930 2931 BX.UploaderUtils.slice = function (file, start, end) { 2932 var blob = null; 2933 if ('mozSlice' in file) blob = file.mozSlice(start, end);else if ('webkitSlice' in file) blob = file.webkitSlice(start, end);else if ('slice' in file) blob = file.slice(start, end);else blob = file.Slice(start, end, file.type); 2934 return blob; 2935 }; 2936 2937 BX.UploaderUtils.readFile = function (file, callback, method) { 2938 if (window["FileReader"]) { 2939 var fileReader = new FileReader(); 2940 fileReader.onload = fileReader.onerror = callback;
2941 method = method || 'readAsDataURL'; 2942 2943 if (fileReader[method]) { 2944 fileReader[method](file); 2945 return fileReader; 2946 } 2947 } 2948 2949 return false; 2950 }; 2951 })(window); 2952 2953 var UploaderQueue = window.BX["UploaderQueue"]; 2954 var UploaderUtils = window.BX["UploaderUtils"]; 2955 2956 var Uploader = /*#__PURE__*/function () { 2957 function Uploader(params) { 2958 babelHelpers.classCallCheck(this, Uploader); 2959 babelHelpers.defineProperty(this, "fileInput", null); 2960 babelHelpers.defineProperty(this, "form", null); 2961 babelHelpers.defineProperty(this, "limits", {}); 2962 babelHelpers.defineProperty(this, "packages", new Map()); 2963 var input = params.input, 2964 uploadFileUrl = params.uploadFileUrl, 2965 id = params.id, 2966 CID = params.CID, 2967 controlId = params.controlId, 2968 dropZone = params.dropZone, 2969 placeHolder = params.placeHolder, 2970 events = params.events; 2971 2972 if (main_core.Type.isStringFilled(uploadFileUrl)) { 2973 this.uploadFileUrl = uploadFileUrl; 2974 } 2975 2976 input = main_core.Type.isStringFilled(input) ? document.getElementById(input) : input; 2977 2978 if (main_core.Type.isDomNode(input)) { 2979 this.fileInput = input; 2980 this.form = input.form; 2981 this.uploadFileUrl = this.uploadFileUrl || this.form.getAttribute('action'); 2982 } else if (input !== null) { 2983 main_core.Runtime.debug(main_core.Loc.getMessage('UPLOADER_INPUT_IS_NOT_DEFINED')); 2984 return; 2985 } 2986 2987 if (!this.uploadFileUrl) { 2988 main_core.Runtime.debug(main_core.Loc.getMessage('UPLOADER_ACTION_URL_NOT_DEFINED')); 2989 return; 2990 } 2991 2992 this.constructor.justCounter++; 2993 var uniqueId = UploaderUtils.getId(); 2994 this.id = main_core.Type.isStringFilled(id) ? id : ['bitrixUploaderID', uniqueId].join(''); 2995 this.CID = main_core.Type.isStringFilled(CID) ? CID : 'CID' + uniqueId; // this is a security id 2996 2997 this.controlId = controlId || 'bitrixUploader'; // this is a control id can be lice control name 2998 2999 this.onChange = this.onChange.bind(this); 3000 this.setLimits(params); 3001 this.initParams(params); 3002 this.init(this.fileInput); 3003 this.dropZone = this.initDropZone(dropZone); 3004 this.bindUserEvents(events); 3005 this.initFilesQueue(params); 3006 BX.onCustomEvent(window, 'onUploaderIsInited', [this.id, this]); 3007 Uploader.repo.set(this.id, this); 3008 } 3009 3010 babelHelpers.createClass(Uploader, [{ 3011 key: "setLimits", 3012 value: function setLimits(_ref) { 3013 var uploadMaxFilesize = _ref.uploadMaxFilesize, 3014 uploadFileWidth = _ref.uploadFileWidth, 3015 uploadFileHeight = _ref.uploadFileHeight, 3016 allowUpload = _ref.allowUpload, 3017 allowUploadExt = _ref.allowUploadExt; 3018 this.limits = { 3019 uploadMaxFilesize: uploadMaxFilesize || 0, 3020 uploadFileWidth: uploadFileWidth || 0, 3021 uploadFileHeight: uploadFileHeight || 0, 3022 uploadFileExt: '', 3023 uploadFile: this.fileInput ? this.fileInput.getAttribute('accept') : '', 3024 allowUpload: allowUpload, 3025 //compatibility 3026 allowUploadExt: allowUploadExt //compatibility 3027 3028 }; 3029 var acceptAttribute = []; 3030 3031 if (main_core.Type.isStringFilled(this.limits['uploadFile'])) { 3032 acceptAttribute.push(this.limits['uploadFile']); 3033 } 3034 3035 if (allowUpload === 'I') { 3036 acceptAttribute.push('image/*'); 3037 } 3038 3039 if (main_core.Type.isStringFilled(allowUploadExt)) { 3040 var separator = allowUploadExt.indexOf(',') >= 0 ? ',' : ' '; 3041 var extensions = []; 3042 allowUploadExt.split(separator).forEach(function (extension) { 3043 extensions.push(extension.trim().replace('.', '')); 3044 acceptAttribute.push('.' + extension.trim().replace('.', '')); 3045 }); 3046 3047 if (extensions) { 3048 this.limits["uploadFileExt"] = extensions; 3049 } 3050 } 3051 3052 this.limits['uploadFile'] = acceptAttribute.join(', '); 3053 } 3054 }, { 3055 key: "initParams", 3056 value: function initParams(_ref2) { 3057 var uploadMethod = _ref2.uploadMethod, 3058 uploadFormData = _ref2.uploadFormData, 3059 filesInputMultiple = _ref2.filesInputMultiple, 3060 uploadInputName = _ref2.uploadInputName, 3061 uploadInputInfoName = _ref2.uploadInputInfoName, 3062 deleteFileOnServer = _ref2.deleteFileOnServer, 3063 pasteFileHashInForm = _ref2.pasteFileHashInForm; 3064 // Limits 3065 this.params = { 3066 filesInputMultiple: this.fileInput && this.fileInput["multiple"] || filesInputMultiple ? "multiple" : false, 3067 uploadFormData: uploadFormData === "N" ? "N" : "Y", 3068 uploadMethod: uploadMethod === "immediate" ? "immediate" : "deferred", 3069 uploadInputName: main_core.Type.isStringFilled(uploadInputName) ? uploadInputName : 'bxu_files', 3070 uploadInputInfoName: main_core.Type.isStringFilled(uploadInputInfoName) ? uploadInputInfoName : 'bxu_info', 3071 deleteFileOnServer: !(deleteFileOnServer === false || deleteFileOnServer === "N"), 3072 //to insert hash into the form 3073 filesInputName: this.fileInput && this.fileInput["name"] ? this.fileInput["name"] : "FILES", 3074 pasteFileHashInForm: !(pasteFileHashInForm === false || pasteFileHashInForm === "N") 3075 }; 3076 } 3077 }, { 3078 key: "init", 3079 value: function init(fileInput) { 3080 if (fileInput === null) { 3081 return true; 3082 } 3083 3084 if (main_core.Type.isDomNode(fileInput)) { 3085 var newFileInput = this.makeFileInput(fileInput); 3086 3087 if (fileInput === this.fileInput) { 3088 this.fileInput = newFileInput; 3089 } 3090 3091 if (newFileInput) { 3092 return true; 3093 } 3094 } 3095 3096 return false;
3097 } 3098 }, { 3099 key: "initDropZone", 3100 value: function initDropZone(dropZoneNode) { 3101 var _this = this; 3102 3103 var dropZone = new DropZone(dropZoneNode); 3104 main_core_events.EventEmitter.subscribe(dropZone, Options.getEventName('caught'), function (_ref3) { 3105 var data = _ref3.data; 3106 3107 _this.onChange(data); 3108 }); 3109 main_core_events.EventEmitter.subscribe(this, Options.getEventName('destroy'), function () { 3110 main_core_events.EventEmitter.unsubscribeAll(dropZone, Options.getEventName('caught')); 3111 dropZone.destroy(); 3112 }); 3113 return dropZone; 3114 } 3115 }, { 3116 key: "initFilesQueue", 3117 value: function initFilesQueue(_ref4) { 3118 var fields = _ref4.fields, 3119 copies = _ref4.copies, 3120 placeHolder = _ref4.placeHolder, 3121 showImage = _ref4.showImage, 3122 sortItems = _ref4.sortItems, 3123 thumb = _ref4.thumb, 3124 queueFields = _ref4.queueFields; 3125 var params = { 3126 fields: queueFields && queueFields['fields'] ? queueFields['fields'] : fields, 3127 copies: queueFields && queueFields['copies'] ? queueFields['copies'] : copies, 3128 placeHolder: queueFields && queueFields['placeHolder'] ? queueFields['placeHolder'] : placeHolder, 3129 showImage: queueFields && queueFields['showImage'] ? queueFields['showImage'] : showImage, 3130 sortItems: queueFields && queueFields['sortItems'] ? queueFields['sortItems'] : sortItems, 3131 thumb: queueFields && queueFields['thumb'] ? queueFields['thumb'] : thumb 3132 }; 3133 this.queue = new UploaderQueue(params, this.limits, this); 3134 } 3135 }, { 3136 key: "bindUserEvents", 3137 value: function bindUserEvents(events) { 3138 if (!main_core.Type.isPlainObject(events)) { 3139 return; 3140 } 3141 3142 for (var eventName in events) { 3143 if (events.hasOwnProperty(eventName)) { 3144 main_core_events.EventEmitter.subscribe(this, eventName, events[eventName]); 3145 } 3146 } 3147 } 3148 }, { 3149 key: "makeFileInput", 3150 value: function makeFileInput(oldFileInput) { 3151 if (!main_core.Type.isDomNode(oldFileInput)) { 3152 return false; 3153 } 3154 3155 main_core.Event.unbindAll(oldFileInput, 'change'); 3156 var newFileInput = oldFileInput.cloneNode(true); 3157 newFileInput.value = ''; 3158 newFileInput.setAttribute('name', this.params["uploadInputName"] + '[]'); 3159 newFileInput.setAttribute('multiple', this.params["filesInputMultiple"]); 3160 newFileInput.setAttribute('accept', this.limits["uploadFile"]); 3161 oldFileInput.parentNode.replaceChild(newFileInput, oldFileInput); 3162 BX.onCustomEvent(this, "onFileinputIsReinited", [newFileInput, this]); 3163 main_core.Event.bind(newFileInput, "change", this.onChange); 3164 return newFileInput; 3165 } 3166 }, { 3167 key: "onChange", 3168 value: function onChange(event) { 3169 if (!event) { 3170 return; 3171 } 3172 3173 if (event['preventDefault']) { 3174 event.preventDefault(); 3175 } 3176 3177 if (event['stopPropagation']) { 3178 event.stopPropagation(); 3179 } 3180 3181 var files = []; 3182 3183 if (main_core.Type.isArray(event)) { 3184 files = event; 3185 } else if (main_core.Type.isObject(event)) { 3186 if (event['target']) { 3187 var fileInput = event['target']; 3188 files = fileInput.files; 3189 3190 if (!fileInput || fileInput.disabled) { 3191 return false; 3192 } 3193 3194 BX.onCustomEvent(this, "onFileinputIsChanged", [fileInput, this]); 3195 this.init(fileInput); 3196 } else if (event['files']) { 3197 files = event['files']; 3198 } 3199 } 3200 3201 this.onAttach(files); 3202 return false; 3203 } 3204 }, { 3205 key: "onAttach", 3206 value: function onAttach(files, nodes, check) { 3207 var _this2 = this; 3208 3209 if (!files || !files['length']) { 3210 return false; 3211 } 3212 3213 check = check !== false; 3214 files = babelHelpers.toConsumableArray(files); 3215 nodes = nodes && main_core.Type.isArray(nodes) ? babelHelpers.toConsumableArray(nodes) : []; 3216 BX.onCustomEvent(this, "onAttachFiles", [files, nodes, this]); 3217 var added = false;
3218 babelHelpers.toConsumableArray(files).forEach(function (file, index) { 3219 var ext = ''; 3220 var type = (file['type'] || '').toLowerCase(); 3221 3222 if (main_core.Type.isDomNode(file) && file.value) { 3223 ext = (file.value.name || '').split('.').pop(); 3224 } else { 3225 ext = (file['name'] || file['tmp_url'] || '').split('.').pop(); 3226 3227 if (ext.indexOf('?') > 0) { 3228 ext = ext.substr(0, ext.indexOf('?')); 3229 } 3230 } 3231 3232 ext = ext.toLowerCase(); 3233 3234 if (check) { 3235 var errors = []; 3236 3237 if (_this2.limits['uploadFile'].indexOf('image/') >= 0 && type.indexOf('image/') < 0 && Options.getImageExtensions().indexOf(ext) < 0) { 3238 errors.push('File type is not an image like.'); 3239 } 3240 3241 if (_this2.limits['uploadFileExt'].length > 0) { 3242 if (_this2.limits['uploadFileExt'].indexOf(ext) < 0) { 3243 errors.push("File extension ".concat(ext, " is in ").concat(_this2.limits['uploadFileExt'])); 3244 } else { 3245 errors.pop(); 3246 } 3247 } 3248 3249 if (_this2.limits['uploadMaxFilesize'] > 0 && file.size > _this2.limits['uploadMaxFilesize']) { 3250 errors.push("File size ".concat(file.size, " is bigger than ").concat(_this2.limits['uploadMaxFilesize'])); 3251 } 3252 3253 if (errors.length > 0) { 3254 return; 3255 } 3256 } 3257
3258 if (String['normalize']) { 3259 file.name = String(file.name).normalize(); 3260 } 3261 3262 BX.onCustomEvent(_this2, "onItemIsAdded", [file, nodes[index] || null, _this2]); 3263 added = true; 3264 }); 3265 3266 if (added && this.params["uploadMethod"] === "immediate") { 3267 this.submit(); 3268 } 3269 3270 return false; 3271 } 3272 }, { 3273 key: "getFormData", 3274 value: function getFormData() { 3275 var formData = new FormData(this.params["uploadFormData"] === "Y" && this.form ? this.form : undefined); 3276 var entries = formData.entries(); 3277 var entry; 3278 3279 while ((entry = entries.next()) && entry.done === false) { 3280 var _entry$value = babelHelpers.slicedToArray(entry.value, 1), 3281 name = _entry$value[0]; 3282 3283 if (name.indexOf(this.params["filesInputName"]) === 0 || name.indexOf(this.params["uploadInputInfoName"]) === 0 || name.indexOf(this.params["uploadInputName"]) === 0) { 3284 formData.delete(name); 3285 } 3286 } 3287 3288 formData.append('AJAX_POST', 'Y'); 3289 formData.append('USER_ID', main_core.Loc.getMessage('USER_ID')); 3290 formData.append('sessid', BX.bitrix_sessid()); 3291 3292 if (BX.message.SITE_ID) { 3293 formData.append('SITE_ID', BX.message.SITE_ID); 3294 } 3295 3296 formData.append(this.params["uploadInputInfoName"] + '[controlId]', this.controlId); 3297 formData.append(this.params["uploadInputInfoName"] + '[CID]', this.CID); 3298 formData.append(this.params["uploadInputInfoName"] + '[uploadInputName]', this.params["uploadInputName"]); 3299 formData.append(this.params["uploadInputInfoName"] + '[version]', Options.getVersion()); 3300 return formData; 3301 } 3302 }, { 3303 key: "submit", 3304 value: function submit() { 3305 var _this3 = this; 3306 3307 //region Compatibility 3308 if (this.queue.itForUpload.length <= 0) { 3309 BX.onCustomEvent(this, 'onStart', [null, { 3310 filesCount: 0 3311 }, this]); 3312 BX.onCustomEvent(this, 'onDone', [null, null, { 3313 filesCount: 0 3314 }]); 3315 BX.onCustomEvent(this, 'onFinish', [null, null, { 3316 filesCount: 0 3317 }]); 3318 return; 3319 } //endregion 3320 3321 3322 var files = Object.values(this.queue.itForUpload.items); 3323 var formData = this.getFormData(); //region Here we can change formData 3324 3325 var changedData = {}; 3326 var buffer1 = { 3327 post: { 3328 data: changedData, 3329 size: 0, 3330 filesCount: files.length 3331 }, 3332 //compatibility field 3333 filesCount: files.length 3334 }; 3335 var eventOnPackageIsInitialized = new main_core_events.BaseEvent(); 3336 eventOnPackageIsInitialized.setCompatData([buffer1, this.queue.itForUpload]); 3337 eventOnPackageIsInitialized.setData({ 3338 formData: formData, 3339 data: changedData, 3340 files: files 3341 }); 3342 main_core_events.EventEmitter.emit(this, 'onPackageIsInitialized', eventOnPackageIsInitialized); 3343 appendToForm(formData, buffer1.post.data); 3344 3345 if (buffer1.post.data !== changedData) { 3346 appendToForm(formData, changedData); 3347 } //endregion 3348 3349 3350 var packageId = 'pIndex' + (new Date().valueOf() + Math.round(Math.random() * 1000000)); 3351 formData.append(this.params["uploadInputInfoName"] + '[packageIndex]', packageId); 3352 formData.append(this.params["uploadInputInfoName"] + '[mode]', 'upload'); 3353 formData.append(this.params["uploadInputInfoName"] + '[filesCount]', files.length); 3354 3355 if (this.packages.size <= 0) { 3356 console.group('Upload'); 3357 } 3358 3359 console.log('1. Create a new Package'); 3360 var packItem = new Package({ 3361 id: packageId, 3362 formData: formData, 3363 files: files, 3364 uploadFileUrl: this.uploadFileUrl, 3365 uploadInputName: this.params["uploadInputName"] 3366 }); 3367 this.queue.itForUpload = new UploaderUtils.Hash(); 3368 var eventOnStart = new main_core_events.BaseEvent(); 3369 eventOnStart.setCompatData([packageId, Object.assign({ 3370 post: { 3371 data: packItem.data, 3372 filesCount: files.length 3373 } 3374 }, packItem), this]); 3375 eventOnStart.setData({ 3376 package: packItem 3377 }); 3378 main_core_events.EventEmitter.emit(this, 'onStart', eventOnStart); 3379 this.packages.set(packItem.getId(), packItem); 3380 main_core_events.EventEmitter.emit(this, 'onBusy'); 3381 packItem.subscribeOnce('done', function (_ref5) { 3382 var p = _ref5.target, 3383 status = _ref5.data.status; 3384 var evDone = new main_core_events.BaseEvent(); 3385 evDone.setCompatData([{}, packageId, packItem, packItem.getServerResponse()]); 3386 evDone.setData({ 3387 package: packItem, 3388 response: packItem.getServerResponse() 3389 }); 3390 main_core_events.EventEmitter.emit(_this3, 'onDone', evDone); // region Compatibility 3391 3392 if (status === 'failed') { 3393 main_core_events.EventEmitter.emit(_this3, 'onError', new main_core_events.BaseEvent({ 3394 compatData: [{}, packageId, packItem.getServerResponse()] 3395 })); 3396 } // endregion Compatibility 3397 3398 3399 _this3.packages.delete(p.getId()); 3400 3401 if (_this3.packages.size <= 0) { 3402 setTimeout(function () { 3403 var ev = new main_core_events.BaseEvent(); 3404 ev.setCompatData([{}, packageId, packItem, packItem.getServerResponse()]); 3405 ev.setData({ 3406 package: packItem, 3407 response: packItem.getServerResponse() 3408 }); 3409 main_core_events.EventEmitter.emit(_this3, 'onFinish', ev); 3410 console.groupEnd('Upload'); 3411 }); 3412 } 3413 }); 3414 packItem.subscribe('fileIsUploaded', function (_ref6) { 3415 var _ref6$data = _ref6.data, 3416 itemId = _ref6$data.itemId, 3417 item = _ref6$data.item, 3418 response = _ref6$data.response; 3419 3420 _this3.queue.itUploaded.setItem(itemId, item); 3421 3422 BX.onCustomEvent(_this3, 'onFileIsUploaded', [itemId, item, response]); 3423 BX.onCustomEvent(item, 'onUploadDone', [item, response, _this3, packItem.getId()]); 3424 }); 3425 packItem.subscribe('fileIsErrored', function (_ref7) { 3426 var _ref7$data = _ref7.data, 3427 itemId = _ref7$data.itemId, 3428 item = _ref7$data.item, 3429 response = _ref7$data.response; 3430 3431 _this3.queue.itFailed.setItem(itemId, item); 3432 3433 BX.onCustomEvent(_this3, 'onFileIsUploadedWithError', [itemId, item, response, _this3, packItem.getId()]); 3434 BX.onCustomEvent(item, 'onUploadError', [item, response, _this3, packItem.getId()]); 3435 }); 3436 packItem.subscribe('fileIsInProgress', function (_ref8) { 3437 var _ref8$data = _ref8.data, 3438 item = _ref8$data.item, 3439 percent = _ref8$data.percent; 3440 BX.onCustomEvent(item, 'onUploadProgress', [item, percent, _this3, packItem.getId()]); 3441 }); 3442 3443 if (packItem.prepare()) {
3444 files.forEach(function (item) { 3445 BX.onCustomEvent(item, 'onUploadStart', [item, 0, _this3, packItem.getId()]); 3446 }); 3447 Streams.addPackage(packItem); 3448 } 3449 } 3450 }, { 3451 key: "log", 3452 value: function log(text) {} 3453 }, { 3454 key: "destruct", 3455 value: function destruct() { 3456 main_core_events.EventEmitter.emit(this, Options.getEventName('destroy')); 3457 delete this.dropZone; 3458 } 3459 /*region Compatbility */ 3460 3461 }, { 3462 key: "getItem", 3463 3464 /*endregion*/ 3465 value: function getItem(id) { 3466 return this.queue.getItem(id); 3467 } 3468 }, { 3469 key: "getItems", 3470 value: function getItems() { 3471 return this.queue.items; 3472 } 3473 }, { 3474 key: "restoreItems", 3475 value: function restoreItems() { 3476 //Todo check it 3477 this.queue.restoreFiles.apply(this.queue, arguments); 3478 } 3479 }, { 3480 key: "clear", 3481 value: function clear() { 3482 var item; 3483 3484 while ((item = this.queue.items.getFirst()) && item) { 3485 item.deleteFile(); 3486 } 3487 } 3488 }, { 3489 key: "controlID", 3490 get: function get() { 3491 return this.controlId; 3492 } 3493 }, { 3494 key: "dialogName", 3495 get: function get() { 3496 return "BX.Uploader"; 3497 } 3498 }, { 3499 key: "length", 3500 get: function get() { 3501 return this.queue.itForUpload.length; 3502 } 3503 }, { 3504 key: "streams", 3505 get: function get() { 3506 var _this4 = this; 3507 3508 if (!this['#_streams']) { 3509 this['#_streams'] = { 3510 packages: { 3511 getItem: function getItem(id) { 3512 return _this4.packages.get(id); 3513 } 3514 } 3515 }; 3516 } 3517 3518 return this['#_streams']; 3519 } 3520 }], [{ 3521 key: "getById", 3522 value: function getById(id) { 3523 return this.repo.get(id); 3524 } 3525 }, { 3526 key: "getInstanceById", 3527 value: function getInstanceById(id) { 3528 return this.repo.get(id); 3529 } 3530 }, { 3531 key: "getInstanceName", 3532 value: function getInstanceName() { 3533 return 'BX.Uploader'; 3534 } 3535 }]); 3536 return Uploader; 3537 }(); 3538 3539 babelHelpers.defineProperty(Uploader, "repo", new Map()); 3540 babelHelpers.defineProperty(Uploader, "justCounter", 0); 3541 babelHelpers.defineProperty(Uploader, "getInstance", function (params) { 3542 BX.onCustomEvent(window, "onUploaderIsAlmostInited", ['BX.Uploader', params]); 3543 return new this(params); 3544 }); 3545 3546 var Manager = /*#__PURE__*/function () { 3547 function Manager() { 3548 babelHelpers.classCallCheck(this, Manager); 3549 } 3550 3551 babelHelpers.createClass(Manager, null, [{ 3552 key: "getById", 3553 value: function getById(id) { 3554 return Uploader.getById(id); 3555 } 3556 }]); 3557 return Manager; 3558 }(); 3559 3560 exports.UploaderManager = Manager; 3561 exports.Uploader = Uploader; 3562 3563}((this.BX = this.BX || {}),BX,BX.Event)); 3564//# sourceMappingURL=uploader.js.map 3565 3566/* End */ 3567; 3568; /* Start:"a:4:{s:4:"full";s:58:"/bitrix/js/main/core/core_uploader/file.js?178694347238495";s:6:"source";s:42:"/bitrix/js/main/core/core_uploader/file.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/ 3569;(function(window){ 3570 window.BX = window['BX'] || {}; 3571 if (window.BX["UploaderFile"]) 3572 return false; 3573 var getOrientation = (function(){ 3574 var exif = { 3575 tags : { 3576 // 0x0100 : "ImageWidth", 3577 // 0x0101 : "ImageHeight", 3578 // 0x8769 : "ExifIFDPointer", 3579 // 0x8825 : "GPSInfoIFDPointer", 3580 // 0xA005 : "InteroperabilityIFDPointer", 3581 // 0x0102 : "BitsPerSample", 3582 // 0x0103 : "Compression", 3583 // 0x0106 : "PhotometricInterpretation", 3584 0x0112 : "Orientation", 3585 // 0x0115 : "SamplesPerPixel", 3586 // 0x011C : "PlanarConfiguration", 3587 // 0x0212 : "YCbCrSubSampling", 3588 // 0x0213 : "YCbCrPositioning", 3589 // 0x011A : "XResolution", 3590 // 0x011B : "YResolution", 3591 // 0x0128 : "ResolutionUnit", 3592 // 0x0111 : "StripOffsets", 3593 // 0x0116 : "RowsPerStrip", 3594 // 0x0117 : "StripByteCounts", 3595 // 0x0201 : "JPEGInterchangeFormat", 3596 // 0x0202 : "JPEGInterchangeFormatLength", 3597 // 0x012D : "TransferFunction", 3598 // 0x013E : "WhitePoint", 3599 // 0x013F : "PrimaryChromaticities", 3600 // 0x0211 : "YCbCrCoefficients", 3601 // 0x0214 : "ReferenceBlackWhite", 3602 // 0x0132 : "DateTime", 3603 // 0x010E : "ImageDescription", 3604 // 0x010F : "Make", 3605 // 0x0110 : "Model", 3606 // 0x0131 : "Software", 3607 // 0x013B : "Artist", 3608 // 0x8298 : "Copyright" 3609 }, 3610 getStringFromDB : function (buffer, start, length) { 3611 var outstr = "", n; 3612 for (n = start; n < start+length; n++) { 3613 outstr += String.fromCharCode(buffer.getUint8(n)); 3614 } 3615 return outstr; 3616 }, 3617 readTags : function(file, tiffStart, dirStart, strings, bigEnd) { 3618 var entries = file.getUint16(dirStart, !bigEnd), 3619 tags = {}, 3620 entryOffset, tag, 3621 i, 3622 l = 0; 3623 for (i in strings) 3624 { 3625 if (strings.hasOwnProperty(i)) 3626 l++; 3627 } 3628 3629 for (i = 0; i < entries; i++) 3630 { 3631 entryOffset = dirStart + i*12 + 2; 3632 tag = strings[file.getUint16(entryOffset, !bigEnd)];
3633 tags[tag] = exif.readTagValue(file, entryOffset, tiffStart, dirStart, bigEnd); 3634 l--; 3635 if (l <= 0) 3636 break; 3637 } 3638 return tags; 3639 }, 3640 readTagValue : function(file, entryOffset, tiffStart, dirStart, bigEnd) { 3641 var type = file.getUint16(entryOffset+2, !bigEnd), 3642 numValues = file.getUint32(entryOffset+4, !bigEnd), 3643 valueOffset = file.getUint32(entryOffset+8, !bigEnd) + tiffStart, 3644 offset, 3645 vals, val, n, 3646 numerator, denominator; 3647 3648 switch (type) 3649 { 3650 case 1: // byte, 8-bit unsigned int 3651 case 7: // undefined, 8-bit byte, value depending on field 3652 if (numValues == 1) { 3653 return file.getUint8(entryOffset + 8, !bigEnd); 3654 } else { 3655 offset = numValues > 4 ? valueOffset : (entryOffset + 8); 3656 vals = []; 3657 for (n=0;n<numValues;n++) { 3658 vals[n] = file.getUint8(offset + n); 3659 } 3660 return vals; 3661 } 3662 case 2: // ascii, 8-bit byte 3663 offset = numValues > 4 ? valueOffset : (entryOffset + 8); 3664 return exif.getStringFromDB(file, offset, numValues-1); 3665 case 3: // short, 16 bit int 3666 if (numValues == 1) { 3667 return file.getUint16(entryOffset + 8, !bigEnd); 3668 } else { 3669 offset = numValues > 2 ? valueOffset : (entryOffset + 8); 3670 vals = []; 3671 for (n=0;n<numValues;n++) { 3672 vals[n] = file.getUint16(offset + 2*n, !bigEnd); 3673 } 3674 return vals; 3675 } 3676 case 4: // long, 32 bit int 3677 if (numValues == 1) { 3678 return file.getUint32(entryOffset + 8, !bigEnd); 3679 } else { 3680 vals = []; 3681 for (n=0;n<numValues;n++) { 3682 vals[n] = file.getUint32(valueOffset + 4*n, !bigEnd); 3683 } 3684 return vals; 3685 } 3686 case 5: // rational = two long values, first is numerator, second is denominator 3687 if (numValues == 1) { 3688 numerator = file.getUint32(valueOffset, !bigEnd); 3689 denominator = file.getUint32(valueOffset+4, !bigEnd); 3690 val = new Number(numerator / denominator); 3691 val.numerator = numerator; 3692 val.denominator = denominator; 3693 return val; 3694 } else { 3695 vals = []; 3696 for (n=0;n<numValues;n++) { 3697 numerator = file.getUint32(valueOffset + 8*n, !bigEnd); 3698 denominator = file.getUint32(valueOffset+4 + 8*n, !bigEnd); 3699 vals[n] = new Number(numerator / denominator); 3700 vals[n].numerator = numerator; 3701 vals[n].denominator = denominator; 3702 } 3703 return vals; 3704 } 3705 case 9: // slong, 32 bit signed int 3706 if (numValues == 1) { 3707 return file.getInt32(entryOffset + 8, !bigEnd); 3708 } else { 3709 vals = []; 3710 for (n=0;n<numValues;n++) { 3711 vals[n] = file.getInt32(valueOffset + 4*n, !bigEnd); 3712 } 3713 return vals; 3714 } 3715 case 10: // signed rational, two slongs, first is numerator, second is denominator 3716 if (numValues == 1) { 3717 return file.getInt32(valueOffset, !bigEnd) / file.getInt32(valueOffset+4, !bigEnd); 3718 } else { 3719 vals = []; 3720 for (n=0;n<numValues;n++) { 3721 vals[n] = file.getInt32(valueOffset + 8*n, !bigEnd) / file.getInt32(valueOffset+4 + 8*n, !bigEnd); 3722 } 3723 return vals; 3724 } 3725 } 3726 }, 3727 readData : function (file, start) { 3728 if (exif.getStringFromDB(file, start, 4) != "Exif") 3729 { 3730 return false; 3731 } 3732 3733 var bigEnd, 3734 tiffOffset = start + 6; 3735 3736 // test for TIFF validity and endianness 3737 if (file.getUint16(tiffOffset) == 0x4949) 3738 { 3739 bigEnd = false; 3740 } 3741 else if (file.getUint16(tiffOffset) == 0x4D4D) 3742 { 3743 bigEnd = true; 3744 } 3745 else 3746 { 3747 return false; 3748 } 3749 3750 if (file.getUint16(tiffOffset+2, !bigEnd) != 0x002A) 3751 { 3752 return false; 3753 } 3754 3755 var firstIFDOffset = file.getUint32(tiffOffset + 4, !bigEnd); 3756 3757 if (firstIFDOffset < 0x00000008) 3758 { 3759 return false; 3760 } 3761 3762 return exif.readTags(file, tiffOffset, tiffOffset + firstIFDOffset, exif.tags, bigEnd); 3763 }, 3764 readBase64 : function (base64) 3765 { 3766 base64 = base64.replace(/^data\:([^\;]+)\;base64,/gmi, ''); 3767 var binary_string = window.atob(base64), //decode base64 3768 len = binary_string.length,
3769 bytes = new Uint8Array(len); 3770 for (var i = 0; i < len; i++) { 3771 bytes[i] = binary_string.charCodeAt(i); 3772 } 3773 var dataView = new DataView(bytes.buffer); 3774 if ((dataView.getUint8(0) != 0xFF) || (dataView.getUint8(1) != 0xD8)) 3775 { 3776 return false; // not a valid jpeg 3777 } 3778 3779 var offset = 2, 3780 length = bytes.buffer.byteLength, 3781 marker, 3782 result = false; 3783 while (offset < length) 3784 { 3785 if (dataView.getUint8(offset) != 0xFF) { 3786 break; // not a valid marker, something is wrong 3787 } 3788 3789 marker = dataView.getUint8(offset + 1); 3790 3791 // we could implement handling for other markers here, 3792 // but we're only looking for 0xFFE1 for EXIF data 3793 3794 if (marker == 225) 3795 { 3796 result = exif.readData(dataView, offset + 4, dataView.getUint16(offset + 2) - 2); 3797 break; 3798 } 3799 else 3800 { 3801 offset += 2 + dataView.getUint16(offset+2); 3802 } 3803 } 3804 return result; 3805 } 3806 }; 3807 return function(base64){ 3808 if (BX.type.isString(base64)) 3809 { 3810 try { 3811 var tags = exif.readBase64(base64); 3812 if(tags && tags["Orientation"]) 3813 return tags["Orientation"]; 3814 } 3815 catch (e) 3816 { 3817 } 3818 } 3819 return false; 3820 }; 3821 })(), 3822 setOrientation = function(image, cnv, ctx, exifOrientation) { 3823 var width = image.width, 3824 height = image.height; 3825 if ([5,6,7,8].indexOf(exifOrientation) >= 0) 3826 { 3827 width = image.height; 3828 height = image.width; 3829 } 3830 3831 BX.adjust(cnv, {props: {width: width, height: height}}); 3832 3833 ctx.save(); 3834 switch(exifOrientation) { 3835 case 2: 3836 // $img.addClass('flip'); 3837 ctx.scale(-1, 1); 3838 ctx.translate(-cnv.width, 0); 3839 break; 3840 case 3: 3841 // $img.addClass('rotate-180'); 3842 ctx.translate(cnv.width, cnv.height); 3843 ctx.rotate(Math.PI); 3844 break; 3845 case 4: 3846 // $img.addClass('flip-and-rotate-180'); 3847 ctx.scale(-1, 1); 3848 ctx.translate(0, cnv.height); 3849 ctx.rotate(Math.PI); 3850 break; 3851 case 5: 3852 // $img.addClass('flip-and-rotate-90'); 3853 ctx.scale(-1, 1); 3854 ctx.translate(0, 0); 3855 ctx.rotate(Math.PI / 2); 3856 break; 3857 case 6: 3858 // $img.addClass('rotate-90'); 3859 ctx.translate(cnv.width, 0); 3860 ctx.rotate(Math.PI / 2); 3861 break; 3862 case 7: 3863 // $img.addClass('flip-and-rotate-90'); 3864 ctx.scale(-1, 1); 3865 ctx.translate(-cnv.width, cnv.height); 3866 ctx.rotate(Math.PI * 3 / 2); 3867 break; 3868 case 8: 3869 // $img.addClass('rotate-270'); 3870 ctx.translate(0, cnv.height); 3871 ctx.rotate(Math.PI * 3 / 2); 3872 break; 3873 } 3874 ctx.drawImage(image, 0, 0); 3875 ctx.restore(); 3876 }; 3877 var BX = window.BX, 3878 statuses = { "new" : 0, ready : 1, preparing : 2, inprogress : 3, done : 4, failed : 5, stopped : 6, changed : 7, uploaded : 8}, 3879 cnvConstr = (function(){ 3880 var cnvConstructor = function(timelimit) { 3881 this.timeLimit = (typeof timelimit === "number" && timelimit > 0 ? timelimit : 50); 3882 this.status = statuses.ready; 3883 this.queue = new BX.UploaderUtils.Hash(); 3884 this.id = (new Date()).getTime(); 3885 }; 3886 cnvConstructor.prototype = { 3887 counter : 0, 3888 active : null, 3889 image : null, 3890 getImage : function() { 3891 if (!this.image) 3892 this.image = new Image(); 3893 return this.image; 3894 }, 3895 canvas : null, 3896 getCanvas : function() { 3897 if (!this.canvas) 3898 { 3899 this.canvas = BX.create('CANVAS', {style : {display: "none"}}); 3900 document.body.appendChild(this.canvas); 3901 } 3902 3903 return this.canvas; 3904 }, 3905 context : null, 3906 getContext : function() { 3907 if (!this.context && this.getCanvas()["getContext"]) 3908 this.context = this.getCanvas().getContext('2d'); 3909 return this.context; 3910 }, 3911 reader : null, 3912 getReader : function() { 3913 if (!this.reader && window["FileReader"]) 3914 this.reader = new FileReader(); 3915 return this.reader; 3916 }, 3917 load : function(file, callback, id, callbackFail) { 3918 if (this.active !== null || (this.getReader() && this.getReader().readyState == 1)) 3919 return; 3920 3921 this.counter++; 3922 this.active = file; 3923 var image = this.getImage(); 3924 BX.unbindAll(image); 3925 image.onload = function(){}; 3926 image.onerror = function(){}; 3927 3928 /* Almost all browsers cache images from local resource except of FF on 06.03.2017. It appears that 3929 FF collect src and does not abort image uploading when src is changed. And we had a bug when in 3930 onload event we got e.target.src of one element but source of image was from '/bitrix/images/1.gif'. */ 3931 // TODO check if chrome and other browsers cache local files for now. If it does not then delete next 2 strings 3932 if (!BX.browser.IsFirefox()) 3933 image.src = '/bitrix/images/1.gif'; 3934 3935 /** For Garbage collector */ 3936 this.onload = null; 3937 delete this.onload; 3938 this.onerror = null; 3939 delete this.onerror; 3940 3941 this.onload = BX.delegate(function(e){ 3942 if (e && e.target && e.target.src && e.target.src.substr(-20) == "/bitrix/images/1.gif") 3943 return; 3944 if (!!callback) 3945 { 3946 try { 3947 callback(BX.proxy_context, this.getCanvas(), this.getContext(), getOrientation((((e && e.target && e.target.src) ? e.target.src : (BX.proxy_context || null))))); 3948 } 3949 catch (e) 3950 { 3951 BX.debug(e); 3952 } 3953 } 3954 if (!!id) 3955 { 3956 this.queue.removeItem(id); 3957 setTimeout(BX.proxy(function() { 3958 this.active = null; 3959 this.exec(); 3960 }, this), this.timeLimit); 3961 } 3962 else 3963 this.active = null; 3964 }, this); 3965 this.onerror = BX.delegate(function(){ 3966 if (!!callbackFail) 3967 { 3968 try 3969 { 3970 callbackFail(BX.proxy_context); 3971 } 3972 catch (e) 3973 { 3974 BX.debug(e); 3975 } 3976 } 3977 if (!!id) 3978 { 3979 this.queue.removeItem(id); 3980 setTimeout(BX.proxy(function() { 3981 this.active = null; 3982 this.exec(); 3983 }, this), this.timeLimit); 3984 } 3985 else 3986 this.active = null; 3987 }, this); 3988 3989 image.name = file.name; 3990 3991 image.onload = this.onload; 3992 image.onerror = this.onerror; 3993 3994 var res = Object.prototype.toString.call(file); 3995 if (file["tmp_url"]) 3996 { 3997 image.src = file["tmp_url"] + (file["tmp_url"].indexOf("?") > 0 ? '&' : '?') + 'imageUploader' + this.id + this.counter; 3998 } 3999 else if (res !== '[object File]' && res !== '[object Blob]') 4000 {
4001 this.onerror(null); 4002 } 4003 else if (window["URL"]) 4004 { 4005 image.src = window["URL"]["createObjectURL"](file); 4006 } 4007 else if (this.getReader() !== null) 4008 { 4009 this.__readerOnLoad = null; 4010 delete this.__readerOnLoad; 4011 this.__readerOnLoad = BX.delegate(function(e) { 4012 this.__readerOnLoad = null; 4013 delete this.__readerOnLoad; 4014 image.src = e.target.result; 4015 }, this); 4016 this.getReader().onloadend = this.__readerOnLoad; 4017 this.getReader().onerror = BX.proxy(function(e) { this.onerror(null); }, this); 4018 this.getReader().readAsDataURL(file); 4019 } 4020 }, 4021 push : function(file, callback, failCallback) { 4022 var id = BX.UploaderUtils.getId(); 4023 this.queue.setItem(id, [id, file, callback, failCallback]); 4024 this.exec(); 4025 }, 4026 exec : function() { 4027 var item = this.queue.getFirst(); 4028 if (!!item) 4029 this.load(item[1], item[2], item[0], item[3]); 4030 }, 4031 pack : function(fileType) { 4032 return BX.UploaderUtils.dataURLToBlob(this.getCanvas().toDataURL(fileType)); 4033 } 4034 }; 4035 return cnvConstructor; 4036 })(); 4037 BX.UploaderFileCnvConstr = cnvConstr; 4038 BX.UploaderFileFileLoader = (function(){ 4039 var d = function(timelimit) { 4040 this.timeLimit = (typeof timelimit === "number" && timelimit > 0 ? timelimit : 50); 4041 this.status = statuses.ready; 4042 this.queue = new BX.UploaderUtils.Hash(); 4043 this._exec = BX.delegate(this.exec, this); 4044 }; 4045 d.prototype = { 4046 xhr : null, 4047 goToNext : function(id) 4048 { 4049 delete this.xhr; 4050 this.xhr = null; 4051 this.queue.removeItem(id); 4052 this.status = statuses.ready; 4053 setTimeout(this._exec, this.timeLimit); 4054 }, 4055 load : function(id, path, onsuccess, onfailure) 4056 { 4057 if (this.status != statuses.ready) 4058 return; 4059 this.status = statuses.inprogress; 4060 var _this = this; 4061 this.xhr = BX.ajax({ 4062 'method': 'GET', 4063 'data' : '', 4064 'url': path, 4065 'onsuccess': function(blob){if (blob === null){onfailure(blob);} else {onsuccess(blob);} _this.goToNext(id);}, 4066 'onfailure': function(blob){onfailure(blob); _this.goToNext(id);}, 4067 'start': false, 4068 'preparePost':false, 4069 'processData':false 4070 }); 4071 this.xhr.withCredentials = true; 4072 this.xhr.responseType = 'blob'; 4073 4074 this.xhr.send(); 4075 }, 4076 push : function(path, onsuccess, onfailure) 4077 { 4078 var id = BX.UploaderUtils.getId(); 4079 this.queue.setItem(id, [id, path, onsuccess, onfailure]); 4080 this.exec(); 4081 }, 4082 exec : function() 4083 { 4084 var item = this.queue.getFirst(); 4085 if (!!item) 4086 this.load(item[0], item[1], item[2], item[3]); 4087 } 4088 }; 4089 return d; 4090 })(); 4091 var prvw = new cnvConstr(), upld = new cnvConstr(), edtr = new cnvConstr(), canvas = BX.create('CANVAS'), ctx; 4092 /** 4093 * @return {BX.UploaderFile} 4094 * @file file 4095 * @params array 4096 * @limits array 4097 * @caller {BX.Uploader} 4098 * You should work with params["fields"] in case you want to change visual part 4099 */ 4100 var mobileNames = {}; 4101 BX.UploaderFile = function (file, params, limits, caller) 4102 { 4103 this.dialogName = (this.dialogName ? this.dialogName : "BX.UploaderFile"); 4104 this.file = file; 4105 this.id = (file['id'] || 'file' + BX.UploaderUtils.getId()); 4106 this.name = file.name; 4107 this.isNode = false; 4108 if (BX.type.isDomNode(file)) 4109 { 4110 this.isNode = true; 4111 this.name = BX.UploaderUtils.getFileNameOnly(file.value); 4112 if (/\[(.+?)\]/.test(file.name)) 4113 { 4114 var tmp = /\[(.+?)\]/.exec(file.name); 4115 this.id = tmp[1]; 4116 } 4117 this.file.bxuHandler = this; 4118 } 4119 else if (file["tmp_url"] && !file["name"]) 4120 { 4121 this.name = BX.UploaderUtils.getFileNameOnly(file["tmp_url"]); 4122 } 4123 this.preview = '<span id="' + this.id + 'Canvas" class="bx-bxu-canvas"></span>'; 4124 this.nameWithoutExt = (this.name.lastIndexOf('.') > 0 ? this.name.substr(0, this.name.lastIndexOf('.')) : this.name); 4125 this.ext = this.name.substr(this.nameWithoutExt.length + 1); 4126 4127 if (/iPhone|iPad|iPod/i.test(navigator.userAgent) && this.nameWithoutExt == "image") 4128 { 4129 var nameWithoutExt = 'mobile_' + BX.date.format("Ymd_His"); 4130 mobileNames[nameWithoutExt] = (mobileNames[nameWithoutExt] || 0); 4131 this.nameWithoutExt = nameWithoutExt + (mobileNames[nameWithoutExt] > 0 ? ("_" + mobileNames[nameWithoutExt]) : ""); 4132 this.name = this.nameWithoutExt + (BX.type.isNotEmptyString(this.ext) ? ("." + this.ext) : ""); 4133 mobileNames[nameWithoutExt]++; 4134 } 4135 4136 this.size = ''; 4137 if (file.size) 4138 this.size = BX.UploaderUtils.getFormattedSize(file.size, 0); 4139 this.type = file.type; 4140 this.status = statuses["new"]; 4141 this.limits = limits; 4142 this.caller = caller; 4143 this.fields = { 4144 thumb : { 4145 tagName : 'SPAN', 4146 template : '<div class="someclass">#preview#<div>#name#</div>', 4147 editorTemplate : '<div class="someeditorclass"><div>#name#</div>', 4148 className : "bx-bxu-thumb-thumb", 4149 placeHolder : null 4150 }, 4151 preview : { 4152 params : { width : 400, height : 400 },
4153 template : "#preview#", 4154 editorParams : { width : 1024, height : 860 }, 4155 editorTemplate : '<span>#preview#</span>', 4156 className : "bx-bxu-thumb-preview", 4157 placeHolder : null, 4158 events : { 4159 click : BX.delegate(this.clickFile, this) 4160 }, 4161 type : "html" 4162 }, 4163 name : { 4164 template : "#name#", 4165 editorTemplate : '<span><input type="text" name="name" value="#name#" /></span>', 4166 className : "bx-bxu-thumb-name", 4167 placeHolder : null 4168 }, 4169 type : { 4170 template : "#type#", 4171 editorTemplate : '#type#', 4172 className : "bx-bxu-thumb-type", 4173 placeHolder : null 4174 } 4175 }; 4176 4177 if (!!params["fields"]) 4178 { 4179 var ij, key; 4180 for (var ii in params["fields"]) 4181 { 4182 if (params["fields"].hasOwnProperty(ii)) 4183 { 4184 if (!!this.fields[ii]) 4185 { 4186 for (ij in params["fields"][ii]) 4187 { 4188 if (params["fields"][ii].hasOwnProperty(ij)) 4189 { 4190 this.fields[ii][ij] = params["fields"][ii][ij]; 4191 } 4192 } 4193 } 4194 else 4195 this.fields[ii] = params["fields"][ii]; 4196 key = ii + ''; 4197 if (key.toLowerCase() != "thumb" && key.toLowerCase() != "preview") 4198 { 4199 this[key.toLowerCase()] = (!!params["fields"][ii]["value"] ? params["fields"][ii]["value"] : ""); 4200 this.log(key.toLowerCase() + ': ' + this[key.toLowerCase()]); 4201 } 4202 } 4203 } 4204 } 4205 4206 BX.onCustomEvent(this, "onFileIsCreated", [this.id, this, this.caller]); 4207 BX.onCustomEvent(this.caller, "onFileIsCreated", [this.id, this, this.caller]); 4208 4209 this.makePreview(); 4210 this.preparationStatus = statuses.done; 4211 return this; 4212 }; 4213 BX.UploaderFile.prototype = { 4214 getId: function() 4215 { 4216 return this.id; 4217 }, 4218 4219 log : function(text) 4220 { 4221 BX.UploaderUtils.log('file ' + this.name, text); 4222 }, 4223 makeThumb : function() 4224 { 4225 var template = this.fields.thumb.template, name, ii, events = {}, node, jj; 4226 for (ii in this.fields) 4227 { 4228 if (this.fields.hasOwnProperty(ii)) 4229 { 4230 if (this.fields[ii].template && this.fields[ii].template.indexOf('#' + ii + '#') >= 0) 4231 { 4232 name = this.id + ii.toUpperCase().substr(0, 1) + ii.substr(1); 4233 node = this.setProps(ii, this[ii], true); 4234 template = template.replace('#' + ii + '#', '<span id="' + name + '" class="' + this.fields[ii]["className"] + '">' + ( 4235 BX.type.isNotEmptyString(node.html) ? node.html.replace("#", "<\x19>") : node.html) + '</span>'); 4236 for (jj in node.events) 4237 { 4238 if (node.events.hasOwnProperty(jj)) 4239 { 4240 events[jj] = node.events[jj]; 4241 } 4242 } 4243 if (!!this.fields[ii].events) 4244 events[name] = this.fields[ii].events; 4245 } 4246 } 4247 } 4248 var res, patt = [], repl = [], tmp; 4249 while ((res = /#([^\\<\\>\\"\\']+?)#/gi.exec(template)) && !!res) 4250 { 4251 if (this[res[1]] !== undefined) 4252 { 4253 template = template.replace(res[0], BX.type.isNotEmptyString(this[res[1]]) ? this[res[1]].replace("#", "<\x19>") : this[res[1]]); 4254 } 4255 else 4256 { 4257 tmp = "<\x18" + patt.length + ">"; 4258 patt.push(tmp); 4259 repl.push(res[0]); 4260 template = template.replace(res[0], tmp); 4261 } 4262 } 4263 while ((res = patt.shift()) && res) 4264 { 4265 tmp = repl.shift(); 4266 template = template.replace(res, tmp); 4267 } 4268 template = template.replace("<\x19>", "#"); 4269 if (!!this.fields.thumb.tagName) 4270 { 4271 res = BX.create(this.fields.thumb.tagName, { 4272 attrs : { 4273 id : (this.id + 'Thumb'), 4274 className : this.fields.thumb.className 4275 }, 4276 events : this.fields.thumb.events, 4277 html : template 4278 } 4279 ); 4280 } 4281 else 4282 { 4283 res = template; 4284 } 4285 this.__makeThumbEventsObj = events; 4286 this.__makeThumbEvents = BX.delegate(function() 4287 { 4288 var ii, jj; 4289 for (ii in events) 4290 { 4291 if (events.hasOwnProperty(ii) && BX(ii)) 4292 { 4293 for (jj in events[ii]) 4294 { 4295 if (events[ii].hasOwnProperty(jj)) 4296 { 4297 BX.bind(BX(ii), jj, events[ii][jj]); 4298 } 4299 } 4300 } 4301 } 4302 this.__makeThumbEvents = null; 4303 delete this.__makeThumbEvents; 4304 }, this); 4305 BX.addCustomEvent(this, "onFileIsAppended", this.__makeThumbEvents); 4306 4307 if (BX.type.isDomNode(this.file)) 4308 { 4309 if (BX.type.isString(template)) 4310 { 4311 this.__bindFileNode = BX.delegate(function(id) 4312 { 4313 var node = BX(id + 'Item'); 4314 if (node.tagName == 'TR') 4315 node.cells[0].appendChild(this.file); 4316 else if (node.tagName == 'TABLE') 4317 node.rows[0].cells[0].appendChild(this.file); 4318 else 4319 BX(id + 'Item').appendChild(this.file); 4320 this.__bindFileNode = null; 4321 delete this.__bindFileNode; 4322 }, this); 4323 BX.addCustomEvent(this, "onFileIsAppended", this.__bindFileNode); 4324 } 4325 else 4326 { 4327 res.appendChild(this.file); 4328 } 4329 } 4330 return res; 4331 }, 4332 checkProps : function() 4333 { 4334 var el2 = BX.UploaderUtils.FormToArray({elements : [BX.proxy_context]}), ii; 4335 for (ii in el2.data) 4336 { 4337 if (el2.data.hasOwnProperty(ii)) 4338 this[ii] = el2.data[ii]; 4339 } 4340 }, 4341 setProps : function(name, val, bReturn) 4342 { 4343 if (typeof name == "string") 4344 { 4345 if (name == "size") 4346 val = BX.UploaderUtils.getFormattedSize(this.file.size, 0); 4347 if (typeof this[name] != "undefined" && typeof this.fields[name] != "undefined") 4348 { 4349 this[name] = val; 4350 var template = this.fields[name].template.
4351 replace('#' + name + '#', this.fields[name]["type"] === "html" ? (val || '') : BX.util.htmlspecialchars(val || '')). 4352 replace(/#id#/gi, this.id), 4353 fii, fjj, el, result = {html : template, events : {}}; 4354 4355 this.hiddenForm = (!!this.hiddenForm ? this.hiddenForm : BX.create("FORM", { style : { display : "none" } } )); 4356 this._checkProps = (!!this._checkProps ? this._checkProps : BX.delegate(this.checkProps, this)); 4357 this.hiddenForm.innerHTML = template; 4358 if (this.hiddenForm.elements.length > 0) 4359 { 4360 for (fii = 0; fii < this.hiddenForm.elements.length; fii++) 4361 { 4362 el = this.hiddenForm.elements[fii]; 4363 if (typeof this[el.name] != "undefined") 4364 { 4365 if (!el.hasAttribute("id")) 4366 el.setAttribute("id", this.id + name + BX.UploaderUtils.getId()); 4367 result.events[el.id] = { 4368 blur : this._checkProps 4369 } 4370 4371 } 4372 } 4373 result.html = this.hiddenForm.innerHTML; 4374 } 4375 if (BX(this.hiddenForm)) 4376 BX.remove(this.hiddenForm); 4377 this.hiddenForm = null; 4378 delete this.hiddenForm; 4379 if (bReturn) 4380 return result; 4381 var node = this.getPH(name); 4382 if (!!node) 4383 { 4384 node.innerHTML = result.html; 4385 for (fii in result.events) 4386 { 4387 if (result.events.hasOwnProperty(fii)) 4388 { 4389 for (fjj in result.events[fii]) 4390 { 4391 if (result.events[fii].hasOwnProperty(fjj)) 4392 { 4393 BX.bind(BX(fii), fjj, result.events[fii][fjj]); 4394 } 4395 } 4396 } 4397 } 4398 } 4399 } 4400 } 4401 else if (!!name) 4402 { 4403 for (var ij in name) 4404 { 4405 if (name.hasOwnProperty(ij)) 4406 { 4407 if (this.fields.hasOwnProperty(ij) && ij !== "preview") 4408 this.setProps(ij, name[ij]); 4409 } 4410 } 4411 } 4412 return true; 4413 }, 4414 getProps : function(name) 4415 { 4416 if (name == "canvas") 4417 { 4418 return BX(this.id + "ProperCanvas"); 4419 } 4420 else if (typeof name == "string") 4421 { 4422 return this[name]; 4423 } 4424 var data = {}; 4425 for (var ii in this.fields) 4426 { 4427 if (this.fields.hasOwnProperty(ii) && (ii !== "preview" && ii !== "thumb")) 4428 { 4429 data[ii] = this[ii]; 4430 } 4431 } 4432 data["size"] = this.file["size"]; 4433 data["type"] = this["type"]; 4434 if (!!this.copies) 4435 { 4436 var copy; 4437 data["canvases"] = {}; 4438 while ((copy = this.copies.getNext()) && !!copy) 4439 { 4440 data["canvases"][copy.id] = { width : copy.width, height : copy.height, name : copy.id }; 4441 } 4442 } 4443 return data; 4444 }, 4445 getThumbs : function() 4446 { 4447 return null; 4448 }, 4449 getPH : function(name) 4450 { 4451 name = (typeof name === "string" ? name : ""); 4452 name = name.toLowerCase(); 4453 if (this.fields.hasOwnProperty(name)) 4454 { 4455 var id = name.substr(0, 1).toUpperCase() + name.substr(1); 4456 this.fields[name]["placeHolder"] = BX(this.id + id); 4457 return this.fields[name]["placeHolder"]; 4458 } 4459 return null; 4460 }, 4461 clickFile : function () 4462 { 4463 return false; 4464 }, 4465 makePreview: function() 4466 { 4467 this.status = statuses.ready; 4468 BX.onCustomEvent(this, "onFileIsInited", [this.id, this, this.caller]); 4469 BX.onCustomEvent(this.caller, "onFileIsInited", [this.id, this, this.caller]); 4470 4471 this.log('is initialized as a file'); 4472 }, 4473 preparationStatus : statuses.ready, 4474 deleteFile: function() 4475 { 4476 var ii, events = this.__makeThumbEventsObj; 4477 for (ii in this.fields) 4478 { 4479 if (this.fields.hasOwnProperty(ii)) 4480 { 4481 if (!!this.fields[ii]["placeHolder"]) 4482 { 4483 this.fields[ii]["placeHolder"] = null; 4484 BX.unbindAll(this.fields[ii]["placeHolder"]); 4485 delete this.fields[ii]["placeHolder"]; 4486 } 4487 } 4488 } 4489 4490 for (ii in events) 4491 { 4492 if (events.hasOwnProperty(ii) && BX(ii)) 4493 { 4494 BX.unbindAll(BX(ii)); 4495 } 4496 } 4497 4498 var removedFile = this.file; 4499 this.file = null; 4500 delete this.file; 4501 4502 BX.remove(this.canvas); 4503 this.canvas = null; 4504 delete this.canvas; 4505 4506 BX.onCustomEvent(this.caller, "onFileIsDeleted", [this.id, this, this.caller, removedFile]); 4507 BX.onCustomEvent(this, "onFileIsDeleted", [this, this.caller]); 4508 } 4509 }; 4510 BX.UploaderImage = function(file, params, limits, caller) 4511 { 4512 this.dialogName = "BX.UploaderImage"; 4513 BX.UploaderImage.superclass.constructor.apply(this, arguments); 4514 this.isImage = true; 4515 this.copies = new BX.UploaderUtils.Hash(); 4516 this.caller = caller; 4517 4518 if (!this.isNode && BX.Uploader.getInstanceName() == "BX.Uploader") 4519 { 4520 if (!!params["copies"]) 4521 { 4522 var copies = params["copies"], copy; 4523 for (var ii in copies) 4524 { 4525 if (copies.hasOwnProperty(ii) && !!copies[ii]) 4526 { 4527 copy = { width : parseInt(copies[ii]['width']), height : parseInt(copies[ii]["height"]), id : ii }; 4528 if (copy['width'] > 0 && copy["height"] > 0) 4529 { 4530 this.copies.setItem(ii, copy); 4531 } 4532 } 4533 } 4534 } 4535 this.preparationStatus = statuses["new"]; 4536 BX.addCustomEvent(this, "onFileHasToBePrepared", BX.delegate(function() 4537 { 4538 this.preparationStatus = statuses.inprogress; 4539 if (this.status !== statuses["new"]) 4540 { 4541 upld.push(this.file, BX.delegate(this.makeCopies, this)); 4542 } 4543 }, this)); 4544 BX.addCustomEvent(this, "onUploadDone", BX.delegate(function() 4545 { 4546 var copy; 4547 while ((copy = this.copies.getNext()) && !!copy) 4548 { 4549 copy.file = null; 4550 delete copy.file; 4551 } 4552 this.preparationStatus = statuses["new"]; 4553 }, this)); 4554 this.canvas = BX.create('CANVAS', {attrs : { id : this.id + "ProperCanvas" } } ); 4555 } 4556 else 4557 { 4558 this.preparationStatus = statuses.done; 4559 this.canvas = null; 4560 } 4561 return this; 4562 }; 4563 BX.extend(BX.UploaderImage, BX.UploaderFile); 4564 BX.UploaderImage.prototype.makePreviewImageWork = function(image, cnv, ctx, exifOrientation) 4565 { 4566 exifOrientation = parseInt(exifOrientation); 4567 4568 var result = null, 4569 width = cnv.width, 4570 height = cnv.height; 4571 4572 if (this.file) 4573 { 4574 this.file.width = cnv.width; 4575 this.file.height = cnv.height; 4576 } 4577 4578 if (!!this.canvas) 4579 { 4580 setOrientation(image, cnv, ctx, exifOrientation); 4581 if (this.file) 4582 { 4583 this.file.width = cnv.width; 4584 this.file.height = cnv.height; 4585 if (exifOrientation) 4586 { 4587 this.file.exif = { 4588 Orientation : exifOrientation 4589 } 4590 } 4591 } 4592 this.applyFile(cnv, false); 4593 result = this.canvas; 4594 } 4595 else if (BX(this.id + 'Canvas')) 4596 { 4597 var res2 = BX.UploaderUtils.scaleImage({width : width, height : height}, this.fields.preview.params), 4598 props = { 4599 props : { width : res2.destin.width, height : res2.destin.height, src : image.src }, 4600 attrs : { 4601 className : (this.file.width > this.file.height ? "landscape" : "portrait") 4602 } 4603 }; 4604 switch (exifOrientation) 4605 { 4606 case 2: 4607 props.attrs.className += ' flip'; break; 4608 case 3: 4609 props.attrs.className += ' rotate-180'; break; 4610 case 4: 4611 props.attrs.className += ' flip-and-rotate-180'; break; 4612 case 5: 4613 props.attrs.className += ' flip-and-rotate-270'; break; 4614 case 6: 4615 props.attrs.className += ' rotate-90'; break; 4616 case 7: 4617 props.attrs.className += ' flip-and-rotate-90'; break; 4618 case 8: 4619 props.attrs.className += ' rotate-270'; break; 4620 } 4621 result = BX.create("IMG", props); 4622 } 4623 4624 BX.onCustomEvent(this, "onFileCanvasIsLoaded", [this.id, this, this.caller, image]); 4625 BX.onCustomEvent(this.caller, "onFileCanvasIsLoaded", [this.id, this, this.caller, image]); 4626 4627 if (BX(this.id + 'Canvas')) 4628 BX(this.id + 'Canvas').appendChild(result); 4629 4630 return result; 4631 }; 4632 4633 BX.UploaderImage.prototype.makePreviewImageLoadHandler = function(image, canvas, context, exifOrientation){ 4634 this.makePreviewImageWork(image, canvas, context, exifOrientation); 4635 this.status = statuses.ready; 4636 4637 BX.onCustomEvent(this, "onFileIsInited", [this.id, this, this.caller]); 4638 BX.onCustomEvent(this.caller, "onFileIsInited", [this.id, this, this.caller]); 4639 this.log('is initialized as an image with preview'); 4640 if (this.preparationStatus == statuses.inprogress) 4641 this.makeCopies(image, canvas, context, exifOrientation); 4642 if (this["_makePreviewImageLoadHandler"]) 4643 { 4644 this._makePreviewImageLoadHandler = null; 4645 delete this._makePreviewImageLoadHandler; 4646 } 4647 if (this["_makePreviewImageFailedHandler"]) 4648 { 4649 this._makePreviewImageFailedHandler = null; 4650 delete this._makePreviewImageFailedHandler; 4651 } 4652 }; 4653 4654 BX.UploaderImage.prototype.makePreviewImageFailedHandler = function(){ 4655 this.status = statuses.ready; 4656 this.preparationStatus = statuses.done; 4657 4658 BX.onCustomEvent(this, "onFileIsInited", [this.id, this, this.caller]); 4659 BX.onCustomEvent(this.caller, "onFileIsInited", [this.id, this, this.caller]); 4660 4661 this.log('is initialized without canvas'); 4662 if (this["_makePreviewImageLoadHandler"]) 4663 { 4664 this._makePreviewImageLoadHandler = null; 4665 delete this._makePreviewImageLoadHandler; 4666 } 4667 if (this["_makePreviewImageFailedHandler"]) 4668 { 4669 this._makePreviewImageFailedHandler = null; 4670 delete this._makePreviewImageFailedHandler; 4671 } 4672 }; 4673 BX.UploaderImage.prototype.makePreview = function() 4674 { 4675 if (!this.isNode) 4676 { 4677 this._makePreviewImageLoadHandler = BX.delegate(this.makePreviewImageLoadHandler, this); 4678 this._makePreviewImageFailedHandler = BX.delegate(this.makePreviewImageFailedHandler, this); 4679 prvw.push(this.file, this._makePreviewImageLoadHandler, this._makePreviewImageFailedHandler); 4680 } 4681 else 4682 { 4683 this.status = statuses.ready; 4684 BX.onCustomEvent(this, "onFileIsInited", [this.id, this, this.caller]); 4685 BX.onCustomEvent(this.caller, "onFileIsInited", [this.id, this, this.caller]); 4686 4687 this.log('is initialized as an image without preview'); 4688 if (this.caller.queue.placeHolder) 4689 { 4690 this._onFileHasGotPreview = BX.delegate(function(id, item) { 4691 4692 BX.removeCustomEvent(this, "onFileHasGotPreview", this._onFileHasGotPreview); 4693 BX.removeCustomEvent(this, "onFileHasNotGotPreview", this._onFileHasNotGotPreview); 4694 4695 this._makePreviewImageLoadHandler = BX.delegate(function(image){ 4696 image = this.makePreviewImageWork(image); 4697 BX.onCustomEvent(this, "onFileHasPreview", [item.id, item, image]); 4698 delete this._makePreviewImageLoadHandler; 4699 delete this._makePreviewImageFailedHandler; 4700 }, this); 4701 this._makePreviewImageFailedHandler = BX.delegate(function(image){ 4702 delete this._makePreviewImageLoadHandler; 4703 delete this._makePreviewImageFailedHandler; 4704 }, this); 4705 prvw.push({tmp_url : item.file.url}, this._makePreviewImageLoadHandler, this._makePreviewImageFailedHandler); 4706 }, this); 4707 this._onFileHasNotGotPreview = BX.delegate(function(id){ 4708 if (id == this.id) 4709 { 4710 BX.removeCustomEvent(this, "onFileHasGotPreview", this._onFileHasGotPreview); 4711 BX.removeCustomEvent(this, "onFileHasNotGotPreview", this._onFileHasNotGotPreview); 4712 } 4713 }, this); 4714 BX.addCustomEvent(this, "onFileHasGotPreview", this._onFileHasGotPreview); 4715 BX.addCustomEvent(this, "onFileHasNotGotPreview", this._onFileHasNotGotPreview); 4716 BX.onCustomEvent(this.caller, "onFileNeedsPreview", [this.id, this, this.caller]); 4717 } 4718 } 4719 return true; 4720 }; 4721 BX.UploaderImage.prototype.checkPreview = function() 4722 { 4723 // TODO check preview 4724 }; 4725 BX.UploaderImage.prototype.applyFile = function(cnv, params) 4726 { 4727 this.checkPreview(); 4728 4729 if (!!params && params.data ) 4730 this.setProps(params.data); 4731 4732 var realScale = BX.UploaderUtils.scaleImage(cnv, {width : this.limits["uploadFileWidth"], height : this.limits["uploadFileHeight"]}), 4733 prvwScale = BX.UploaderUtils.scaleImage(cnv, this.fields.preview.params), 4734 prvwProps = {
4735 props : { width : prvwScale.destin.width, height : prvwScale.destin.height }, 4736 attrs : { 4737 className : "bx-bxu-proper-canvas"+(prvwScale.destin.width > prvwScale.destin.height ? " landscape" : " portrait") 4738 } 4739 }; 4740 4741 if (realScale.bNeedCreatePicture || !!params) 4742 { 4743 BX.adjust(canvas, { props : { width : realScale.destin.width, height : realScale.destin.height } } ); 4744 ctx = canvas.getContext('2d'); 4745 ctx.drawImage(cnv, 4746 realScale.source.x, realScale.source.y, realScale.source.width, realScale.source.height, 4747 realScale.destin.x, realScale.destin.y, realScale.destin.width, realScale.destin.height 4748 ); 4749 4750 var dataURI = canvas.toDataURL(this.file.type); 4751 this.file = BX.UploaderUtils.dataURLToBlob(dataURI); 4752 } 4753 4754 this.file.name = this.name; 4755 this.file.width = realScale.destin.width; 4756 this.file.height = realScale.destin.height; 4757 4758 BX.adjust(this.canvas, prvwProps); 4759 4760 ctx = this.canvas.getContext('2d'); 4761 ctx.drawImage(cnv, 4762 prvwScale.source.x, prvwScale.source.y, prvwScale.source.width, prvwScale.source.height, 4763 prvwScale.destin.x, prvwScale.destin.y, prvwScale.destin.width, prvwScale.destin.height 4764 ); 4765 4766 ctx = null; 4767 cnv = null; 4768 4769 this.setProps('size'); 4770 this.status = statuses.changed; 4771 }; 4772 BX.UploaderImage.prototype.clickFile = function() 4773 { 4774 if (!this.canvas || !BX["CanvasEditor"] || this.status == statuses["new"]) 4775 return false; 4776 if (!this.__showEditor) 4777 { 4778 this.__showEditor = BX.delegate(this.showEditor, this); 4779 this.eFunc = { 4780 "apply" : BX.delegate(this.applyFile, this), 4781 "delete" : BX.delegate(this.deleteFile, this), 4782 "clear" : BX.delegate(function() 4783 { 4784 BX.removeCustomEvent(editor, "onApplyCanvas", this.eFunc["apply"]); 4785 BX.removeCustomEvent(editor, "onDeleteCanvas", this.eFunc["delete"]); 4786 BX.removeCustomEvent(editor, "onClose", this.eFunc["clear"]); 4787 }, this) 4788 }; 4789 } 4790 var template = this.fields.thumb.editorTemplate, name; 4791 for (var ii in this.fields) 4792 { 4793 if (this.fields.hasOwnProperty(ii)) 4794 { 4795 name = ii.substr(0, 1).toUpperCase() + ii.substr(1); 4796 template = template.replace('#' + ii + '#', 4797 (ii === "preview" ? "" : 4798 ('<span id="' + this.id + name + 'Editor" class="' + this.fields[ii]["className"] + '">' + 4799 this.fields[ii]["editorTemplate"].replace('#' + ii + '#', (!!this[ii] ? BX.util.htmlspecialchars(this[ii]) : '')) + '</span>'))); 4800 } 4801 } 4802 4803 BX.adjust(edtr.getCanvas(), { props : { width : this.file.width, height : this.file.height } } ); 4804 edtr.getContext().drawImage(this.canvas, 4805 0, 0, this.canvas.width, this.canvas.height, 4806 0, 0, edtr.getCanvas().width, edtr.getCanvas().height); 4807 var editor = BX.CanvasEditor.show(edtr.getCanvas(), {title : this.name, template : template}); 4808 4809 BX.addCustomEvent(editor, "onApplyCanvas", this.eFunc["apply"]); 4810 BX.addCustomEvent(editor, "onDeleteCanvas", this.eFunc["delete"]); 4811 BX.addCustomEvent(editor, "onClose", this.eFunc["clear"]); 4812 BX.onCustomEvent(this, "onCanvasEditorIsCreated", [editor, this]); 4813 4814 edtr.push(this.file, this.__showEditor); 4815 this.editor = editor; 4816 return false; 4817 }; 4818 BX.UploaderImage.prototype.showEditor = function(image, canvas, context, exifOrientation) 4819 { 4820 BX.adjust(canvas, { props : { width : this.file.width, height : this.file.height } } ); 4821 setOrientation(image, canvas, context, exifOrientation); 4822 this.editor.copyCanvas(canvas); 4823 }; 4824 BX.UploaderImage.prototype.makeCopies = function(image, cnv, ctx, exifOrientation) 4825 { 4826 var copy, res, dataURI, result, 4827 context = canvas.getContext('2d'); 4828 setOrientation(image, canvas, context, exifOrientation); 4829 while ((copy = this.copies.getNext()) && !!copy) 4830 { 4831 res = BX.UploaderUtils.scaleImage(canvas, copy); 4832 BX.adjust(cnv, {props : { width : res.destin.width, height : res.destin.height } } ); 4833 ctx.drawImage(canvas, 4834 res.source.x, res.source.y, res.source.width, res.source.height, 4835 res.destin.x, res.destin.y, res.destin.width, res.destin.height 4836 ); 4837 4838 dataURI = cnv.toDataURL(this.file.type); 4839 result = BX.UploaderUtils.dataURLToBlob(dataURI); 4840 result.width = cnv.width; 4841 result.height = cnv.height; 4842 result.name = this.name; 4843 result.thumb = copy.id; 4844 result.canvases = this.copies.length; 4845 result.canvas = this.copies.pointer - 1; 4846 copy.file = result; 4847 } 4848 this.preparationStatus = statuses.done; 4849 BX.onCustomEvent(this, 'onFileIsPrepared'); 4850 }; 4851 BX.UploaderImage.prototype.getThumbs = function(name) 4852 { 4853 if (name == "getCount") 4854 return this.copies.length; 4855 4856 var res = (typeof name == "string" ? this.copies.getItem(name) : this.copies.getNext()); 4857 4858 if (!!res) 4859 return res.file; 4860 return null; 4861 }; 4862 return true; 4863}(window)); 4864 4865/* End */ 4866; 4867; /* Start:"a:4:{s:4:"full";s:59:"/bitrix/js/main/core/core_uploader/queue.js?178694347218127";s:6:"source";s:43:"/bitrix/js/main/core/core_uploader/queue.js";s:3:"min";s:0:"";s:3:"map";s:0:"";}"*/ 4868;(function(window){ 4869 window.BX = window['BX'] || {}; 4870 if (window.BX["UploaderQueue"]) 4871 return false;
4872 var 4873 BX = window.BX, 4874 statuses = { "new" : 0, ready : 1, preparing : 2, inprogress : 3, done : 4, failed : 5, stopped : 6, changed : 7, uploaded : 8}; 4875 /** 4876 * @return {BX.UploaderQueue} 4877 * @params array 4878 * @params[placeHolder] - DOM node to append files /OL or UL/ 4879 */ 4880 BX.UploaderQueue = function (params, limits, caller) 4881 { 4882 this.dialogName = "BX.UploaderQueue"; 4883 limits = (!!limits ? limits : {}); 4884 4885 this.limits = { 4886 phpPostMaxSize : limits["phpPostMaxSize"], 4887 phpUploadMaxFilesize : limits["phpUploadMaxFilesize"], 4888 uploadMaxFilesize : (limits["uploadMaxFilesize"] > 0 ? limits["uploadMaxFilesize"] : 0), 4889 uploadFileWidth : (limits["uploadFileWidth"] > 0 ? limits["uploadFileWidth"] : 0), 4890 uploadFileHeight : (limits["uploadFileHeight"] > 0 ? limits["uploadFileHeight"] : 0)}; 4891 4892 this.placeHolder = BX(params["placeHolder"]); 4893 this.showImage = (params["showImage"] !== false && params["showImage"] !== 'N'); 4894 this.sortItems = (params["sortItems"] !== false && params["sortItems"] !== 'N'); 4895 this.fileCopies = params["copies"]; 4896 this.fileFields = params["fields"]; 4897 4898 this.uploader = caller; 4899 this.itForUpload = new BX.UploaderUtils.Hash(); 4900 this.items = new BX.UploaderUtils.Hash(); 4901 this.itUploaded = new BX.UploaderUtils.Hash(); 4902 this.itFailed = new BX.UploaderUtils.Hash(); 4903 this.thumb = { tagName : "LI", className : "bx-bxu-thumb-thumb"}; 4904 if (!!params["thumb"]) 4905 { 4906 for (var ii in params["thumb"]) 4907 { 4908 if (params["thumb"].hasOwnProperty(ii) && this.thumb.hasOwnProperty(ii)) 4909 { 4910 this.thumb[ii] = params["thumb"][ii]; 4911 } 4912 } 4913 } 4914 4915 BX.addCustomEvent(caller, "onItemIsAdded", BX.delegate(this.addItem, this)); 4916 BX.addCustomEvent(caller, "onFileIsDeleted", BX.delegate(this.deleteItem, this)); 4917 BX.addCustomEvent(caller, "onFileIsReinited", BX.delegate(this.reinitItem, this)); 4918 4919 this.log('Initialized'); 4920 return this; 4921 }; 4922 BX.UploaderQueue.prototype = { 4923 showError : function(text) { this.log('Error! ' + text); }, 4924 log : function(text) 4925 { 4926 BX.UploaderUtils.log('queue', text); 4927 }, 4928 addItem : function (file, being) 4929 { 4930 var isImage; 4931 if (!this.showImage) 4932 isImage = false; 4933 else if (BX.type.isDomNode(file)) 4934 isImage = BX.UploaderUtils.isImage(file.value, null, null); 4935 else 4936 isImage = BX.UploaderUtils.isImage(file["name"], file["type"], file["size"]); 4937 4938 BX.onCustomEvent(this.uploader, "onFileIsBeforeCreated", [file, being, isImage, this.uploader]); 4939 4940 var params = {copies : this.fileCopies, fields : this.fileFields}, 4941 res = (isImage ? 4942 new BX.UploaderImage(file, params, this.limits, this.uploader) : 4943 new BX.UploaderFile(file, params, this.limits, this.uploader)), 4944 children, node, 4945 itemStatus = {status : statuses.ready}; 4946 4947 BX.onCustomEvent(res, "onFileIsAfterCreated", [res, being, itemStatus, this.uploader]); 4948 BX.onCustomEvent(this.uploader, "onFileIsAfterCreated", [res, being, itemStatus, this.uploader]); 4949 4950 this.items.setItem(res.id, res); 4951 if (being || itemStatus["status"] !== statuses.ready) 4952 { 4953 this.itUploaded.setItem(res.id, res); 4954 } 4955 else 4956 { 4957 this.itForUpload.setItem(res.id, res); 4958 } 4959 if (!!this.placeHolder) 4960 { 4961 if (BX(being)) 4962 { 4963 res.thumbNode = node = BX(being); 4964 node.setAttribute("bx-bxu-item-id", res.id); 4965 } 4966 else 4967 { 4968 children = res.makeThumb(); 4969 node = BX.create(this.thumb.tagName, { 4970 attrs : { 4971 id : res.id + 'Item', 4972 'bx-bxu-item-id' : res.id, 4973 className : this.thumb.className} 4974 }); 4975 if (BX.type.isNotEmptyString(children)) 4976 { 4977 if (this.thumb.tagName == 'TR') 4978 { 4979 children = children.replace(/[\n\t]/gi, "").replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1"); 4980 if (!!children["trim"]) 4981 children = children.trim(); 4982 var replaceFunction = function(str, tdParams, tdInnerHTML) 4983 { 4984 var td = node.insertCell(-1), 4985 attrs = { 4986 colspan : true, 4987 headers : true, 4988 accesskey : true, 4989 "class" : true, 4990 contenteditable : true, 4991 contextmenu : true, 4992 dir : true, 4993 hidden : true, 4994 id : true, 4995 lang : true, 4996 spellcheck : true, 4997 style : true, 4998 tabindex : true, 4999 title : true, 5000 translate : true 5001 }, param; 5002 td.innerHTML = tdInnerHTML; 5003 tdParams = tdParams.split(" "); 5004 while ((param = tdParams.pop()) && param) 5005 { 5006 param = param.split("="); 5007 if (param.length == 2) 5008 { 5009 param[0] = param[0].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1"); 5010 param[1] = param[1].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1"); 5011 if (attrs[param[0]] === true) 5012 td.setAttribute(param[0], param[1]); 5013 else 5014 td[param[0]] = param[1]; 5015 } 5016 } 5017 return ""; 5018 }, regex = /^<td(.*?)>(.*?)<\/td>/i; 5019 window.data1 = children; 5020 while (regex.test(children)) 5021 children = children.replace(regex, replaceFunction); 5022 } 5023 else 5024 { 5025 node.innerHTML = children; 5026 } 5027 } 5028 else if (BX.type.isDomNode(children)) 5029 { 5030 BX.adjust(node, { children : [children] } ); 5031 } 5032 } 5033 5034 if (!!window["jsDD"] && this.sortItems) 5035 { 5036 if (!this._onbxdragstart) 5037 { 5038 this._onbxdragstart = BX.delegate(this.onbxdragstart, this); 5039 this._onbxdragstop = BX.delegate(this.onbxdragstop, this); 5040 this._onbxdrag = BX.delegate(this.onbxdrag, this); 5041 this._onbxdraghout = BX.delegate(this.onbxdraghout, this); 5042 this._onbxdestdraghover = BX.delegate(this.onbxdestdraghover, this); 5043 this._onbxdestdraghout = BX.delegate(this.onbxdestdraghout, this); 5044 this._onbxdestdragfinish = BX.delegate(this.onbxdestdragfinish, this); 5045 } 5046 BX.addClass(node, "bx-drag-draggable"); 5047 node.onbxdragstart = this._onbxdragstart; 5048 node.onbxdragstop = this._onbxdragstop; 5049 node.onbxdrag = this._onbxdrag; 5050 node.onbxdraghout = this._onbxdraghout; 5051 window.jsDD.registerObject(node); 5052 5053 node.onbxdestdraghover = this._onbxdestdraghover; 5054 node.onbxdestdraghout = this._onbxdestdraghout; 5055 node.onbxdestdragfinish = this._onbxdestdragfinish; 5056 window.jsDD.registerDest(node); 5057 var inputs = BX.findChild(node, {tagName : "INPUT", props : {"type" : "text"}}, true, true); 5058 for (var ii = 0; ii <= inputs.length; ii++) 5059 { 5060 BX.bind(inputs[ii], "mousedown", BX.eventCancelBubble); 5061 } 5062 } 5063 node.setAttribute("bx-item-id", res.id); 5064 if (BX(being)) 5065 { 5066 BX.onCustomEvent(this.uploader, "onFileIsBound", [res.id, res, this.caller, being]); 5067 BX.onCustomEvent(res, "onFileIsBound", [res.id, res, this.caller, being]); 5068 } 5069 else if (!!being) 5070 { 5071 this.placeHolder.appendChild(node); 5072 BX.onCustomEvent(this.uploader, "onFileIsAttached", [res.id, res, this.caller, being]); 5073 BX.onCustomEvent(res, "onFileIsAttached", [res.id, res, this.caller, being]); 5074 } 5075 else 5076 { 5077 this.placeHolder.appendChild(node); 5078 BX.onCustomEvent(this.uploader, "onFileIsAppended", [res.id, res, this.caller]); 5079 BX.onCustomEvent(res, "onFileIsAppended", [res.id, res, this.caller]); 5080 } 5081 } 5082 BX.onCustomEvent(this.uploader, "onQueueIsChanged", [this, "add", res.id, res]); 5083 }, 5084 getItem : function(id) 5085 { 5086 var item = this.items.getItem(id); 5087 if (item) 5088 return {item : item, node : (item.thumbNode || BX(id + 'Item'))}; 5089 return null; 5090 }, 5091 onbxdragstart : function() { 5092 var item = BX.proxy_context, 5093 id = (item && item.getAttribute("bx-item-id")); 5094 if (id) 5095 { 5096 var template = item.innerHTML.replace(new RegExp(id, "gi"), "DragCopy"); 5097 item.__dragCopyDiv = BX.create('DIV', { 5098 attrs : { 5099 className : "bx-drag-object " + item.className 5100 }, 5101 style : { 5102 position : "absolute", 5103 zIndex : 10, 5104 width : item.clientWidth + 'px' 5105 }, 5106 html : template 5107 }); 5108 item.__dragCopyPos = BX.pos(item); 5109 BX.onCustomEvent(this.uploader, "onBxDragStart", [item, item.__dragCopyDiv]); 5110 document.body.appendChild(item.__dragCopyDiv); 5111 5112 BX.addClass(item, "bx-drag-source"); 5113 var c = BX('DragCopyProperCanvas'),
5114 c1, 5115 it = this.items.getItem(id); 5116 if (c && (it && BX(it.canvas))) 5117 { 5118 c1 = it.canvas.cloneNode(true); 5119 c.parentNode.replaceChild(c1, c); 5120 c1.getContext("2d").drawImage(it.canvas, 0, 0); 5121 } 5122 } 5123 return true; 5124 }, 5125 onbxdragstop : function() { 5126 var item = BX.proxy_context; 5127 if (item.__dragCopyDiv) 5128 { 5129 BX.removeClass(item, "bx-drag-source"); 5130 item.__dragCopyDiv.parentNode.removeChild(item.__dragCopyDiv); 5131 item.__dragCopyDiv = null; 5132 delete item['__dragCopyDiv']; 5133 delete item['__dragCopyPos']; 5134 } 5135 return true; 5136 }, 5137 onbxdrag : function(x, y) { 5138 var item = BX.proxy_context, 5139 div = item.__dragCopyDiv; 5140 if (div) 5141 { 5142 if (item.__dragCopyPos) 5143 { 5144 if (!item.__dragCopyPos.deltaX) 5145 item.__dragCopyPos.deltaX = item.__dragCopyPos.left - x; 5146 if (!item.__dragCopyPos.deltaY) 5147 item.__dragCopyPos.deltaY = item.__dragCopyPos.top - y; 5148 x += item.__dragCopyPos.deltaX; 5149 y += item.__dragCopyPos.deltaY; 5150 } 5151 5152 div.style.left = x + 'px'; 5153 div.style.top = y + 'px'; 5154 } 5155 }, 5156 onbxdraghout : function(currentNode, x, y) { 5157 }, 5158 onbxdestdraghover : function(currentNode) { 5159 if (!currentNode || !currentNode.hasAttribute("bx-bxu-item-id") || !this.items.hasItem(currentNode.getAttribute("bx-bxu-item-id"))) 5160 return; 5161 var item = BX.proxy_context; 5162 BX.addClass(item, "bx-drag-over"); 5163 return true; 5164 }, 5165 onbxdestdraghout : function() { 5166 var item = BX.proxy_context; 5167 BX.removeClass(item, "bx-drag-over"); 5168 return true; 5169 }, 5170 onbxdestdragfinish : function(currentNode) { 5171 var item = BX.proxy_context; 5172 BX.removeClass(item, "bx-drag-over"); 5173 if(item == currentNode || !BX.hasClass(currentNode, "bx-drag-draggable")) 5174 return true; 5175 var id = currentNode.getAttribute("bx-bxu-item-id"); 5176 if (!this.items.hasItem(id)) 5177 return; 5178 5179 var obj = item.parentNode, 5180 n = obj.childNodes.length, 5181 act, it, buff, j; 5182 5183 for (j=0; j<n; j++) 5184 { 5185 if (obj.childNodes[j] == item) 5186 item.number = j; 5187 else if (obj.childNodes[j] == currentNode) 5188 currentNode.number = j; 5189 5190 if (currentNode.number > 0 && item.number > 0) 5191 break; 5192 } 5193 5194 if (this.itForUpload.hasItem(id)) 5195 { 5196 act = (item.number <= currentNode.number ? "beforeItem" : ( 5197 item.nextSibling ? "afterItem" : "inTheEnd")); 5198 it = null; 5199 if (act != "inTheEnd") 5200 { 5201 for (j = item.number + (act == "beforeItem" ? 0 : 1); j < n; j++) 5202 { 5203 if (this.itForUpload.hasItem(obj.childNodes[j].getAttribute("bx-bxu-item-id"))) 5204 { 5205 it = obj.childNodes[j].getAttribute("bx-bxu-item-id"); 5206 break; 5207 } 5208 } 5209 if (it === null) 5210 act = "inTheEnd"; 5211 } 5212 buff = this.itForUpload.removeItem(currentNode.getAttribute("bx-bxu-item-id")); 5213 if (act != "inTheEnd") 5214 this.itForUpload.insertBeforeItem(buff.id, buff, it); 5215 else 5216 this.itForUpload.setItem(buff.id, buff); 5217 } 5218 5219 act = (item.number <= currentNode.number ? "beforeItem" : ( 5220 item.nextSibling ? "afterItem" : "inTheEnd")); 5221 it = null; 5222 if (act != "inTheEnd") 5223 { 5224 for (j = item.number + (act == "beforeItem" ? 0 : 1); j < n; j++) 5225 { 5226 if (this.items.hasItem(obj.childNodes[j].getAttribute("bx-bxu-item-id"))) 5227 { 5228 it = obj.childNodes[j].getAttribute("bx-bxu-item-id"); 5229 break; 5230 } 5231 } 5232 if (it === null) 5233 act = "inTheEnd"; 5234 } 5235 buff = this.items.removeItem(currentNode.getAttribute("bx-bxu-item-id")); 5236 if (act != "inTheEnd") 5237 this.items.insertBeforeItem(buff.id, buff, it); 5238 else 5239 this.items.setItem(buff.id, buff); 5240 5241 currentNode.parentNode.removeChild(currentNode); 5242 if (item.number <= currentNode.number) 5243 { 5244 item.parentNode.insertBefore(currentNode, item); 5245 } 5246 else if (item.nextSibling) 5247 { 5248 item.parentNode.insertBefore(currentNode, item.nextSibling); 5249 } 5250 else 5251 { 5252 for (j=0; j<n; j++) 5253 { 5254 if (obj.childNodes[j] == item) 5255 item.number = j; 5256 else if (obj.childNodes[j] == currentNode) 5257 currentNode.number = j; 5258 } 5259 if (item.number <= currentNode.number) 5260 { 5261 item.parentNode.insertBefore(currentNode, item); 5262 } 5263 else 5264 { 5265 item.parentNode.appendChild(currentNode); 5266 } 5267 } 5268 BX.onCustomEvent(item, "onFileOrderIsChanged", [item.id, item, this.caller]); 5269 BX.onCustomEvent(this.uploader, "onQueueIsChanged", [this, "sort", item.id, item]); 5270 return true; 5271 }, 5272 deleteItem : function (id, item) { 5273 var pointer = this.getItem(id), node; 5274 if (pointer && (!this.placeHolder || ((node = pointer.node) && node))) 5275 { 5276 if (!!node) 5277 { 5278 if (!!window["jsDD"]) 5279 { 5280 node.onmousedown = null; 5281 node.onbxdragstart = null; 5282 node.onbxdragstop = null; 5283 node.onbxdrag = null; 5284 node.onbxdraghout = null; 5285 node.onbxdestdraghover = null; 5286 node.onbxdestdraghout = null; 5287 node.onbxdestdragfinish = null; 5288 node.__bxpos = null; 5289 5290 window.jsDD.arObjects[node.__bxddid] = null; 5291 delete window.jsDD.arObjects[node.__bxddid]; 5292 5293 window.jsDD.arDestinations[node.__bxddeid] = null; 5294 delete window.jsDD.arDestinations[node.__bxddeid]; 5295 } 5296 BX.unbindAll(node); 5297 if (item["replaced"] !== true) 5298 node.parentNode.removeChild(node); 5299 } 5300 5301 this.items.removeItem(id); 5302 this.itUploaded.removeItem(id); 5303 this.itFailed.removeItem(id); 5304 this.itForUpload.removeItem(id); 5305 BX.onCustomEvent(this.uploader, "onQueueIsChanged", [this, "delete", id, item]); 5306 return true; 5307 } 5308 return false;
5309 }, 5310 reinitItem : function (id, item) { 5311 var node, children; 5312 if (!!this.placeHolder && this.items.hasItem(id) && (node = BX(id + 'Item')) && node) 5313 { 5314 children = item.makeThumb(); 5315 if (BX.type.isNotEmptyString(children)) 5316 { 5317 if (this.thumb.tagName == 'TR') 5318 { 5319 children = children.replace(/[\n\t]/gi, "").replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1"); 5320 if (!!children["trim"]) 5321 children = children.trim(); 5322 var replaceFunction = function(str, tdParams, tdInnerHTML) 5323 { 5324 var td = node.insertCell(-1), 5325 attrs = { 5326 colspan : true, 5327 headers : true, 5328 accesskey : true, 5329 "class" : true, 5330 contenteditable : true, 5331 contextmenu : true, 5332 dir : true, 5333 hidden : true, 5334 id : true, 5335 lang : true, 5336 spellcheck : true, 5337 style : true, 5338 tabindex : true, 5339 title : true, 5340 translate : true 5341 }, param; 5342 td.innerHTML = tdInnerHTML; 5343 tdParams = tdParams.split(" "); 5344 while ((param = tdParams.pop()) && param) 5345 { 5346 param = param.split("="); 5347 if (param.length == 2) 5348 { 5349 param[0] = param[0].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1"); 5350 param[1] = param[1].replace(/^(\s+)(.*?)/gi, "$2").replace(/(.*?)(\s+)$/gi, "$1").replace(/^["'](.*?)["']$/gi, "$1"); 5351 if (attrs[param[0]] === true) 5352 td.setAttribute(param[0], param[1]); 5353 else 5354 td[param[0]] = param[1]; 5355 } 5356 } 5357 return ""; 5358 }, regex = /^<td(.*?)>(.*?)<\/td>/i; 5359 window.data1 = children; 5360 while (regex.test(children)) 5361 children = children.replace(regex, replaceFunction); 5362 } 5363 else 5364 { 5365 node.innerHTML = children; 5366 } 5367 } 5368 else if (BX.type.isDomNode(children)) 5369 { 5370 while (BX(node.firstChild)) 5371 { 5372 BX.remove(node.firstChild); 5373 } 5374 BX.adjust(node, { children : [children] } ); 5375 } 5376 BX.onCustomEvent(this.uploader, "onFileIsAppended", [item.id, item, this.caller]); 5377 BX.onCustomEvent(item, "onFileIsAppended", [item.id, item, this.caller]); 5378 } 5379 }, 5380 clear : function() 5381 { 5382 var item; 5383 while ((item = this.items.getFirst()) && !!item) 5384 this.deleteItem(item.id, item); 5385 }, 5386 restoreFiles : function(data, restoreErrored, startAgain) 5387 { 5388 data.reset(); 5389 var item, copy, erroredFile; 5390 while((item = data.getNext()) && item) 5391 { 5392 erroredFile = this.itFailed.hasItem(item.id); 5393 if (restoreErrored === true) 5394 { 5395 this.itFailed.removeItem(item.id); 5396 } 5397 5398 if (!this.items.hasItem(item.id) || this.itFailed.hasItem(item.id)) 5399 { 5400 continue; 5401 } 5402 5403 if (startAgain === true || startAgain !== false && erroredFile) // for compatibility 5404 { 5405 delete item["uploadStatus"]; 5406 5407 delete item.file["uploadStatus"]; 5408 delete item.file["firstChunk"]; 5409 delete item.file["package"]; 5410 delete item.file["packages"]; 5411 5412 if (item.file["copies"]) 5413 { 5414 item.file["copies"].reset(); 5415 while((copy = item.file["copies"].getNext()) && copy) 5416 { 5417 delete copy["uploadStatus"]; 5418 delete copy["firstChunk"]; 5419 delete copy["package"]; 5420 delete copy["packages"]; 5421 } 5422 item.file["copies"].reset(); 5423 } 5424 item["restored"] = (startAgain === true ? "Y" : "C"); // Start again or continue 5425 } 5426 else 5427 { 5428 if (erroredFile) // If a error was occurred on the last step we should send this piece again 5429 { 5430 if (item.file["package"]) 5431 { 5432 item.file["package"]--; 5433 } 5434 if (item.file["copies"]) 5435 { 5436 item.file["copies"].reset(); 5437 5438 while((copy = item.file["copies"].getNext()) && copy) 5439 { 5440 delete copy["uploadStatus"]; 5441 delete copy["firstChunk"]; 5442 delete copy["package"]; 5443 delete copy["packages"]; 5444 } 5445 item.file["copies"].reset(); 5446 } 5447 } 5448 5449 item["restored"] = "C"; // Continue 5450 } 5451 this.itUploaded.removeItem(item.id); 5452 this.itForUpload.setItem(item.id, item); 5453 BX.onCustomEvent(item, "onUploadRestore", [item]); 5454 } 5455 } 5456 }; 5457 return statuses; 5458}(window)); 5459 5460/* End */ 5461;
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.