1;(function(window){ 2 window.BX = window['BX'] || {}; 3 if (window.BX["UploaderUtils"]) 4 return false; 5 var BX = window.BX; 6 BX.UploaderLog = []; 7 BX.UploaderDebug = false; 8 var statuses = { "new" : 0, ready : 1, preparing : 2, inprogress : 3, done : 4, failed : 5, stopped : 6, changed : 7, uploaded : 8}; 9 BX.UploaderUtils = { 10 statuses : statuses, 11 getId : function() { return (new Date().valueOf() + Math.round(Math.random() * 1000000)); }, 12 log : function(){ 13 if (BX.UploaderDebug === true) 14 { 15 console.log(arguments); 16 } 17 else 18 { 19 BX.UploaderLog.push(arguments); 20 } 21 }, 22 Hash : (function(){ 23 var d = function() { 24 this.length = 0; 25 this.items = {}; 26 this.order = []; 27 var i; 28 if (arguments.length == 1 && BX.type.isArray(arguments[0]) && arguments[0].length > 0) 29 { 30 var data = arguments[0]; 31 for (i = 0; i < data.length; i++) 32 { 33 if (data[i] && typeof data[i] == "object" && data[i]["id"]) 34 { 35 this.setItem(data[i]["id"], data[i]); 36 } 37 } 38 } 39 else 40 { 41 for (i = 0; i < arguments.length; i += 2) 42 this.setItem(arguments[i], arguments[i + 1]); 43 } 44 }; 45 d.prototype = { 46 getIds : function() 47 { 48 return this.order; 49 }, 50 getQueue : function(id) 51 { 52 id += ''; 53 return BX.util.array_search(id, this.order); 54 }, 55 getByOrder : function(order) 56 { 57 return this.getItem(this.order[order]); 58 }, 59 removeItem : function(in_key) 60 { 61 in_key += ''; 62 var tmp_value, number; 63 if (typeof(this.items[in_key]) != 'undefined') { 64 tmp_value = this.items[in_key]; 65 number = this.getQueue(in_key); 66 this.pointer -= (this.pointer >= number ? 1 : 0); 67 delete this.items[in_key]; 68 this.order = BX.util.deleteFromArray(this.order, number); 69 this.length = this.order.length; 70 71 } 72 return tmp_value; 73 }, 74 75 getItem : function(in_key) { 76 in_key += ''; 77 return this.items[in_key]; 78 }, 79 80 unshiftItem : function(in_key, in_value) 81 { 82 in_key += ''; 83 if (typeof(in_value) != 'undefined') 84 { 85 if (typeof(this.items[in_key]) == 'undefined') 86 { 87 this.order.unshift(in_key); 88 this.length = this.order.length; 89 } 90 this.items[in_key] = in_value; 91 } 92 return in_value; 93 }, 94 setItem : function(in_key, in_value) 95 { 96 in_key += ''; 97 if (typeof(in_value) != 'undefined') 98 { 99 if (typeof(this.items[in_key]) == 'undefined') 100 { 101 this.order.push(in_key); 102 this.length = this.order.length; 103 } 104 this.items[in_key] = in_value; 105 } 106 return in_value; 107 }, 108 109 hasItem : function(in_key) 110 { 111 in_key += ''; 112 return typeof(this.items[in_key]) != 'undefined'; 113 }, 114 insertBeforeItem : function(in_key, in_value, after_key) 115 { 116 in_key += ''; 117 if (typeof(in_value) != 'undefined') 118 { 119 if (typeof(this.items[in_key]) == 'undefined') 120 { 121 this.order.splice(this.getQueue(after_key), 0, in_key); 122 this.length = this.order.length; 123 } 124 this.items[in_key] = in_value; 125 } 126 return in_value; 127 }, 128 getFirst : function() 129 { 130 var in_key, item = null; 131 for (var ii = 0; ii < this.order.length; ii++) 132 { 133 in_key = this.order[ii]; 134 if (!!in_key && this.hasItem(in_key)) 135 { 136 item = this.getItem(in_key); 137 break; 138 } 139 } 140 return item; 141 }, 142 getNext : function() 143 { 144 this.pointer = (0 <= this.pointer && this.pointer < this.order.length ? this.pointer : -1); 145 var res = this.getItem(this.order[this.pointer + 1]); 146 if (!!res) 147 this.pointer++; 148 else 149 this.pointer = -1; 150 return res; 151 }, 152 getPrev : function() 153 { 154 this.pointer = (0 <= this.pointer && this.pointer < this.order.length ? this.pointer : 0); 155 var res = this.getItem(this.order[this.pointer - 1]); 156 if (!!res) 157 this.pointer--; 158 return res; 159 }, 160 reset : function() 161 { 162 this.pointer = -1; 163 }, 164 setPointer : function(in_key) 165 { 166 this.pointer = this.getQueue(in_key); 167 return this.pointer; 168 }, 169 getLast : function() 170 { 171 var in_key, item = null; 172 for (var ii = this.order.length; ii >=0; ii--) 173 { 174 in_key = this.order[ii]; 175 if (!!in_key && this.hasItem(in_key)) 176 { 177 item = this.getItem(in_key); 178 break; 179 } 180 } 181 return item; 182 } 183 }; 184 return d; 185 })(), 186 getFileNameOnly : function (name) 187 { 188 var delimiter = "\\", start = name.lastIndexOf(delimiter), finish = name.length; 189 if (start == -1) 190 { 191 delimiter = "/"; 192 start = name.lastIndexOf(delimiter); 193 } 194 if ((start + 1) == name.length) 195 { 196 finish = start; 197 start = name.substring(0, finish).lastIndexOf(delimiter); 198 } 199 name = name.substring(start + 1, finish); 200 if (delimiter == "/" && name.indexOf("?") > 0) 201 { 202 name = name.substring(0, name.indexOf("?")); 203 } 204 205 if (name == '') 206 name = 'noname'; 207 return name; 208 }, 209 isImageExt : function(ext) 210 { 211 return (BX.message('bxImageExtensions') && BX.type.isNotEmptyString(ext) ? 212 (new RegExp('(?:^|\\W)(' + ext + ')(?:\\W|$)', 'gi')).test(BX.message('bxImageExtensions')) : 213 false 214 ); 215 }, 216 isImage : function(name, type, size) 217 { 218 size = BX.type.isNumber(size) ? size : (BX.type.isNotEmptyString(size) && !(/[\D]+/gi.test(size)) ? parseInt(size) : null); 219 return ( 220 (type === null || (type || '').indexOf("image/") === 0) && 221 (size === null || (size < 20 * 1024 * 1024)) && 222 BX.UploaderUtils.isImageExt((name || '').lastIndexOf('.') > 0 ? name.substr(name.lastIndexOf('.')+1).toLowerCase() : '')); 223 }, 224 scaleImage : function(arSourceSize, arSize, resizeType) 225 { 226 var sourceImageWidth = parseInt(arSourceSize["width"]), sourceImageHeight = parseInt(arSourceSize["height"]); 227 resizeType = (!resizeType && !!arSize["type"] ? arSize["type"] : resizeType); 228 arSize = (!!arSize ? arSize : {}); 229 arSize.width = parseInt(!!arSize.width ? arSize.width : 0); 230 arSize.height = parseInt(!!arSize.height ? arSize.height : 0); 231 232 var res = { 233 bNeedCreatePicture : false, 234 source : {x : 0, y : 0, width : 0, height : 0}, 235 destin : {x : 0, y : 0, width : 0, height : 0} 236 }, width, height; 237 238 if (!(sourceImageWidth > 0 || sourceImageHeight > 0)) 239 { 240 BX.DoNothing(); 241 } 242 else 243 {
244 if (!BX.type.isNotEmptyString(resizeType)) 245 { 246 resizeType = "inscribed"; 247 } 248 249 250 var ResizeCoeff, iResizeCoeff; 251 252 if (resizeType.indexOf("proportional") >= 0) 253 { 254 width = Math.max(sourceImageWidth, sourceImageHeight); 255 height = Math.min(sourceImageWidth, sourceImageHeight); 256 } 257 else 258 { 259 width = sourceImageWidth; 260 height = sourceImageHeight; 261 } 262 if (resizeType == "exact") 263 { 264 var 265 ratio = (sourceImageWidth / sourceImageHeight < arSize["width"] / arSize["height"] ? arSize["width"] / sourceImageWidth : arSize["height"] / sourceImageHeight), 266 x = Math.max(0, Math.round(sourceImageWidth / 2 - (arSize["width"] / 2) / ratio)), 267 y = Math.max(0, Math.round(sourceImageHeight / 2 - (arSize["height"] / 2) / ratio)); 268 269 res.bNeedCreatePicture = true; 270 res.coeff = ratio; 271 272 res.destin["width"] = arSize["width"]; 273 res.destin["height"] = arSize["height"]; 274 275 res.source["x"] = x; 276 res.source["y"] = y; 277 res.source["width"] = Math.round(arSize["width"] / ratio, 0); 278 res.source["height"] = Math.round(arSize["height"] / ratio, 0); 279 } 280 else 281 { 282 if (resizeType == "circumscribed") 283 { 284 ResizeCoeff = { 285 width : (width > 0 ? arSize["width"] / width : 1), 286 height: (height > 0 ? arSize["height"] / height : 1)}; 287 288 iResizeCoeff = Math.max(ResizeCoeff["width"], ResizeCoeff["height"], 1); 289 } 290 else 291 { 292 ResizeCoeff = { 293 width : (width > 0 ? arSize["width"] / width : 1), 294 height: (height > 0 ? arSize["height"] / height : 1)}; 295 296 iResizeCoeff = Math.min(ResizeCoeff["width"], ResizeCoeff["height"], 1); 297 iResizeCoeff = (0 < iResizeCoeff ? iResizeCoeff : 1); 298 } 299 res.bNeedCreatePicture = (iResizeCoeff != 1); 300 res.coeff = iResizeCoeff; 301 res.destin["width"] = Math.max(1, parseInt(iResizeCoeff * sourceImageWidth)); 302 res.destin["height"] = Math.max(1, parseInt(iResizeCoeff * sourceImageHeight)); 303 304 res.source["x"] = 0; 305 res.source["y"] = 0; 306 res.source["width"] = sourceImageWidth; 307 res.source["height"] = sourceImageHeight; 308 } 309 310 } 311 return res; 312 }, 313 dataURLToBlob : function(dataURL) 314 { 315 var marker = ';base64,', parts, contentType, raw, rawLength; 316 if(dataURL.indexOf(marker) == -1) { 317 parts = dataURL.split(','); 318 contentType = parts[0].split(':')[1]; 319 raw = parts[1]; 320 return new Blob([raw], {type: contentType}); 321 } 322 323 parts = dataURL.split(marker); 324 contentType = parts[0].split(':')[1]; 325 raw = window.atob(parts[1]); 326 rawLength = raw.length; 327 328 var uInt8Array = new Uint8Array(rawLength); 329 330 for(var i = 0; i < rawLength; ++i) { 331 uInt8Array[i] = raw.charCodeAt(i); 332 } 333 334 return new Blob([uInt8Array], {type: contentType}); 335 }, 336 sizeof : function(obj) { 337 var size = 0, key; 338 for (key in obj) { 339 if (obj.hasOwnProperty(key)) 340 { 341 size += key.length; 342 if (typeof obj[key] == "object") 343 { 344 if (obj[key] === null) 345 BX.DoNothing(); 346 else if (obj[key]["size"] > 0) 347 size += obj[key].size; 348 else 349 size += BX.UploaderUtils.sizeof(obj[key]); 350 } 351 else if (typeof obj[key] == "number") 352 { 353 size += obj[key].toString().length; 354 } 355 else if (!!obj[key] && obj[key].length > 0) 356 { 357 size += obj[key].length; 358 } 359 } 360 } 361 return size; 362 }, 363 FormToArray : function(form, data) 364 { 365 return BX.ajax.prepareForm(form, data); 366 }, 367 getFormattedSize : function (size, precision) 368 { 369 var a = ["b", "Kb", "Mb", "Gb", "Tb"], pos = 0; 370 while(size >= 1024 && pos < 4) 371 { 372 size /= 1024; 373 pos++; 374 } 375 return (Math.round(size * (precision > 0 ? precision * 10 : 1) ) / (precision > 0 ? precision * 10 : 1)) + 376 " " + BX.message("FILE_SIZE_" + a[pos]); 377 }, 378 bindEvents : function(obj, event, func) 379 { 380 var funcs = [], ii; 381 if (typeof func == "string") 382 { 383 eval('funcs.push(' + func + ');'); 384 } 385 else if (!!func["length"] && func["length"] > 0) 386 { 387 for(ii = 0; ii < func.length; ii++) 388 { 389 if (typeof func[ii] == "string") 390 eval('funcs.push(' + func[ii] + ');'); 391 else 392 funcs.push(func[ii]); 393 } 394 } 395 else 396 funcs.push(func); 397 if (funcs.length > 0) 398 { 399 for (ii = 0; ii < funcs.length; ii++) 400 { 401 BX.addCustomEvent(obj, event, funcs[ii]); 402 } 403 } 404 405 }, 406 applyFilePart : function(file, blob) 407 { 408 if (BX.type.isDomNode(file)) 409 { 410 file.uploadStatus = statuses.done; 411 } 412 else if (file == blob) 413 { 414 file.uploadStatus = statuses.done; 415 } 416 else if (file.blobed === true) 417 { 418 file.uploadStatus = ((file.package + 1) >= file.packages ? statuses.done : statuses.inprogress); 419 if (file.uploadStatus == statuses.inprogress) 420 file.package++; 421 } 422 return true; 423 }, 424 getFilePart : function(file, MaxFilesize) 425 { 426 var blob, chunkSize = MaxFilesize, start, end; 427 if (BX.type.isDomNode(file)) 428 { 429 blob = file; 430 } 431 else if (MaxFilesize <= 0 || file.size <= MaxFilesize) 432 { 433 blob = file; 434 } 435 else if (file['packages'] && file['packages'] <= file['package']) 436 { 437 blob = null; 438 } 439 else if (window.Blob || window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder) 440 { 441 if (file['packages']) 442 { 443 file.package++; 444 start = file.package * chunkSize; 445 end = start + chunkSize; 446 } 447 else 448 { 449 file.packages = Math.ceil(file.size / chunkSize); 450 file.package = 0; 451 start = 0; 452 end = chunkSize; 453 } 454 455 if('mozSlice' in file) 456 blob = file.mozSlice(start, end, file.type); 457 else if ('webkitSlice' in file) 458 blob = file.webkitSlice(start, end, file.type); 459 else if ('slice' in file) 460 blob = file.slice(start, end, file.type); 461 else 462 blob = file.Slice(start, end, file.type); 463 464 for (var ii in file) 465 { 466 if (file.hasOwnProperty(ii)) 467 { 468 blob[ii] = file[ii]; 469 } 470 } 471 blob["name"] = file["name"]; 472 blob["start"] = start; 473 blob["package"] = file.package; 474 blob["packages"] = file.packages; 475 } 476 return blob; 477 }, 478 makeAnArray : function(file, data) 479 { 480 file = (!!file ? file : {files : [], props : {}}); 481 var ii; 482 for (var jj in data) 483 { 484 if (data.hasOwnProperty(jj)) 485 { 486 if (typeof data[jj] == "object" && data[jj].length > 0) 487 { 488 file[jj] = (!!file[jj] ? file[jj] : []); 489 for (ii=0; ii<data[jj].length; ii++) 490 { 491 file[jj].push(data[jj][ii]); 492 } 493 } 494 else 495 { 496 497 for (ii in data[jj]) 498 { 499 if (data[jj].hasOwnProperty(ii)) 500 { 501 file[jj] = (!!file[jj] ? file[jj] : {}); 502 file[jj][ii] = data[jj][ii]; 503 } 504 } 505 } 506 } 507 } 508 return file; 509 }, 510 appendToForm : function(fd, key, val) 511 { 512 if (!!val && typeof val == "object") 513 { 514 for (var ii in val) 515 { 516 if (val.hasOwnProperty(ii)) 517 { 518 BX.UploaderUtils.appendToForm(fd, key + '[' + ii + ']', val[ii]); 519 } 520 } 521 } 522 else 523 {
524 fd.append(key, (!!val ? val : '')); 525 } 526 }, 527 FormData : function() 528 { 529 return new (BX.Uploader.getInstanceName() == "BX.UploaderSimple" ? FormDataLocal : window.FormData); 530 }, 531 prepareData : function(arData) 532 { 533 var data = {}; 534 if (null != arData) 535 { 536 if(typeof arData == 'object') 537 { 538 for(var i in arData) 539 { 540 if (arData.hasOwnProperty(i)) 541 { 542 var name = BX.util.urlencode(i); 543 if(typeof arData[i] == 'object') 544 data[name] = BX.UploaderUtils.prepareData(arData[i]); 545 else 546 data[name] = BX.util.urlencode(arData[i]); 547 } 548 } 549 } 550 else 551 data = BX.util.urlencode(arData); 552 } 553 return data; 554 } 555 }; 556 var FormDataLocal = function() 557 { 558 var uniqueID; 559 do { 560 uniqueID = Math.floor(Math.random() * 99999); 561 } while(BX("form-" + uniqueID)); 562 this.local = true; 563 this.form = BX.create("FORM", { 564 props: { 565 id: "form-" + uniqueID, 566 method: "POST", 567 enctype: "multipart/form-data", 568 encoding: "multipart/form-data" 569 }, 570 style: {display: "none"} 571 }); 572 document.body.appendChild(this.form); 573 }; 574 FormDataLocal.prototype = { 575 append : function(name, val) 576 { 577 if (BX.type.isDomNode(val)) 578 { 579 this.form.appendChild(val); 580 } 581 else 582 { 583 this.form.appendChild( 584 BX.create("INPUT", { 585 props : { 586 type : "hidden", 587 name : name, 588 value : val 589 } 590 } 591 ) 592 ); 593 } 594 } 595 }; 596 BX.UploaderUtils.slice = function(file, start, end) 597 { 598 var blob = null; 599 if('mozSlice' in file) 600 blob = file.mozSlice(start, end); 601 else if ('webkitSlice' in file) 602 blob = file.webkitSlice(start, end); 603 else if ('slice' in file) 604 blob = file.slice(start, end); 605 else 606 blob = file.Slice(start, end, file.type); 607 return blob; 608 }; 609 BX.UploaderUtils.readFile = function (file, callback, method) 610 { 611 if (window["FileReader"]) 612 { 613 var fileReader = new FileReader(); 614 fileReader.onload = fileReader.onerror = callback; 615 method = (method || 'readAsDataURL'); 616 if (fileReader[method]) 617 { 618 fileReader[method](file); 619 return fileReader; 620 } 621 } 622 return false; 623 }; 624}(window));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.