1/* 2UploadiFive 1.1.2 3Copyright (c) 2012 Reactive Apps, Ronnie Garcia 4Released under the UploadiFive Standard License <http://www.uploadify.com/uploadifive-standard-license> 5*/ 6(function (b) { 7 var a = { 8 init: function (c) { 9 return this.each(function () { 10 var g = b(this); 11 g.data("uploadifive", { 12 inputs: {}, 13 inputCount: 0, 14 fileID: 0, 15 queue: {count: 0, selected: 0, replaced: 0, errors: 0, queued: 0, cancelled: 0}, 16 uploads: {current: 0, attempts: 0, successful: 0, errors: 0, count: 0} 17 }); 18 var d = g.data("uploadifive"); 19 var f = d.settings = b.extend({ 20 auto: true, 21 buttonClass: false, 22 buttonText: "Select Files", 23 checkScript: false, 24 dnd: true, 25 dropTarget: false, 26 fileObjName: "Filedata", 27 fileSizeLimit: 0, 28 fileType: false, 29 formData: {}, 30 height: 30, 31 itemTemplate: false, 32 method: "post", 33 multi: true, 34 overrideEvents: [], 35 queueID: false, 36 queueSizeLimit: 0, 37 removeCompleted: false, 38 simUploadLimit: /android/i.test(navigator.userAgent) ? 1 : 0, 39 truncateLength: 0, 40 uploadLimit: 0, 41 uploadScript: "uploadifive.php", 42 width: 100 43 }, c); 44 if (isNaN(f.fileSizeLimit)) { 45 var e = parseInt(f.fileSizeLimit) * 1.024; 46 if (f.fileSizeLimit.indexOf("KB") > -1) { 47 f.fileSizeLimit = e * 1000; 48 } else { 49 if (f.fileSizeLimit.indexOf("MB") > -1) { 50 f.fileSizeLimit = e * 1000000; 51 } else { 52 if (f.fileSizeLimit.indexOf("GB") > -1) { 53 f.fileSizeLimit = e * 1000000000; 54 } 55 } 56 } 57 } else { 58 f.fileSizeLimit = f.fileSizeLimit * 1024; 59 } 60 d.inputTemplate = b('<input type="file">').css({ 61 "font-size": f.height + "px", 62 opacity: 0, 63 position: "absolute", 64 right: "-3px", 65 top: "-3px", 66 "z-index": 999 67 }); 68 d.createInput = function () { 69 var j = d.inputTemplate.clone(); 70 var k = j.name = "input" + d.inputCount++; 71 if (f.multi) { 72 j.attr("multiple", true); 73 } 74 j.bind("change", function () { 75 d.queue.selected = 0; 76 d.queue.replaced = 0; 77 d.queue.errors = 0; 78 d.queue.queued = 0; 79 var l = this.files.length; 80 d.queue.selected = l; 81 if ((d.queue.count + l) > f.queueSizeLimit && f.queueSizeLimit !== 0) { 82 if (b.inArray("onError", f.overrideEvents) < 0) { 83 alert("The maximum number of queue items has been reached (" + f.queueSizeLimit + "). Please select fewer files."); 84 } 85 if (typeof f.onError === "function") { 86 f.onError.call(g, "QUEUE_LIMIT_EXCEEDED"); 87 } 88 } else { 89 for (var m = 0; m < l; m++) { 90 file = this.files[m]; 91 d.addQueueItem(file); 92 } 93 d.inputs[k] = this; 94 d.createInput(); 95 } 96 if (f.auto) { 97 a.upload.call(g); 98 } 99 if (typeof f.onSelect === "function") { 100 f.onSelect.call(g, d.queue); 101 } 102 }); 103 if (d.currentInput) { 104 d.currentInput.hide(); 105 } 106 d.button.append(j); 107 d.currentInput = j; 108 }; 109 d.destroyInput = function (j) { 110 b(d.inputs[j]).remove(); 111 delete d.inputs[j]; 112 d.inputCount--; 113 }; 114 d.drop = function (m) { 115 d.queue.selected = 0; 116 d.queue.replaced = 0; 117 d.queue.errors = 0; 118 d.queue.queued = 0; 119 var l = m.dataTransfer; 120 var k = l.name = "input" + d.inputCount++; 121 var j = l.files.length; 122 d.queue.selected = j; 123 if ((d.queue.count + j) > f.queueSizeLimit && f.queueSizeLimit !== 0) { 124 if (b.inArray("onError", f.overrideEvents) < 0) { 125 alert("The maximum number of queue items has been reached (" + f.queueSizeLimit + "). Please select fewer files."); 126 } 127 if (typeof f.onError === "function") { 128 f.onError.call(g, "QUEUE_LIMIT_EXCEEDED"); 129 } 130 } else { 131 for (var o = 0; o < j; o++) { 132 file = l.files[o]; 133 d.addQueueItem(file); 134 } 135 d.inputs[k] = l; 136 } 137 if (f.auto) { 138 a.upload.call(g); 139 } 140 if (typeof f.onDrop === "function") { 141 f.onDrop.call(g, l.files, l.files.length); 142 } 143 m.preventDefault(); 144 m.stopPropagation(); 145 }; 146 d.fileExistsInQueue = function (k) { 147 for (var j in d.inputs) { 148 input = d.inputs[j]; 149 limit = input.files.length; 150 for (var l = 0; l < limit; l++) { 151 existingFile = input.files[l]; 152 if (existingFile.name == k.name && !existingFile.complete) { 153 return true; 154 } 155 } 156 } 157 return false;
158 }; 159 d.removeExistingFile = function (k) { 160 for (var j in d.inputs) { 161 input = d.inputs[j]; 162 limit = input.files.length; 163 for (var l = 0; l < limit; l++) { 164 existingFile = input.files[l]; 165 if (existingFile.name == k.name && !existingFile.complete) { 166 d.queue.replaced++; 167 a.cancel.call(g, existingFile, true); 168 } 169 } 170 } 171 }; 172 if (f.itemTemplate == false) { 173 d.queueItem = b('<div class="uploadifive-queue-item"> <a class="close" href="#">X</a> <div><span class="filename"></span><span class="fileinfo"></span></div> <div class="progress"> <div class="progress-bar"></div> </div> </div>'); 174 } else { 175 d.queueItem = b(f.itemTemplate); 176 } 177 d.addQueueItem = function (k) { 178 if (b.inArray("onAddQueueItem", f.overrideEvents) < 0) { 179 d.removeExistingFile(k); 180 k.queueItem = d.queueItem.clone(); 181 k.queueItem.attr("id", f.id + "-file-" + d.fileID++); 182 k.queueItem.find(".close").bind("click", function () { 183 a.cancel.call(g, k); 184 return false; 185 }); 186 var m = k.name; 187 if (m.length > f.truncateLength && f.truncateLength != 0) { 188 m = m.substring(0, f.truncateLength) + "..."; 189 } 190 k.queueItem.find(".filename").html(m); 191 k.queueItem.data("file", k); 192 d.queueEl.append(k.queueItem); 193 } 194 if (typeof f.onAddQueueItem === "function") { 195 f.onAddQueueItem.call(g, k); 196 } 197 if (f.fileType) { 198 if (b.isArray(f.fileType)) { 199 var j = false; 200 for (var l = 0; l < f.fileType.length; l++) { 201 if (k.type.indexOf(f.fileType[l]) > -1) { 202 j = true; 203 } 204 } 205 if (!j) { 206 d.error("FORBIDDEN_FILE_TYPE", k); 207 } 208 } else { 209 if (k.type.indexOf(f.fileType) < 0) { 210 d.error("FORBIDDEN_FILE_TYPE", k); 211 } 212 } 213 } 214 if (k.size > f.fileSizeLimit && f.fileSizeLimit != 0) { 215 d.error("FILE_SIZE_LIMIT_EXCEEDED", k); 216 } else { 217 d.queue.queued++; 218 d.queue.count++; 219 } 220 }; 221 d.removeQueueItem = function (m, l, k) { 222 if (!k) { 223 k = 0; 224 } 225 var j = l ? 0 : 500; 226 if (m.queueItem) { 227 if (m.queueItem.find(".fileinfo").html() != " - Completed") { 228 m.queueItem.find(".fileinfo").html(" - Cancelled"); 229 } 230 m.queueItem.find(".progress-bar").width(0); 231 m.queueItem.delay(k).fadeOut(j, function () { 232 b(this).remove(); 233 }); 234 delete m.queueItem; 235 d.queue.count--; 236 } 237 }; 238 d.filesToUpload = function () { 239 var k = 0; 240 for (var j in d.inputs) { 241 input = d.inputs[j]; 242 limit = input.files.length; 243 for (var l = 0; l < limit; l++) { 244 file = input.files[l]; 245 if (!file.skip && !file.complete) { 246 k++; 247 } 248 } 249 } 250 return k; 251 }; 252 d.checkExists = function (k) { 253 if (b.inArray("onCheck", f.overrideEvents) < 0) { 254 b.ajaxSetup({async: false}); 255 var j = b.extend(f.formData, {filename: k.name}); 256 b.post(f.checkScript, j, function (l) { 257 k.exists = parseInt(l); 258 }); 259 if (k.exists) { 260 if (!confirm("A file named " + k.name + " already exists in the upload folder.\nWould you like to replace it?")) { 261 a.cancel.call(g, k); 262 return true; 263 } 264 } 265 } 266 if (typeof f.onCheck === "function") { 267 f.onCheck.call(g, k, k.exists); 268 } 269 return false; 270 }; 271 d.uploadFile = function (k, l) { 272 if (!k.skip && !k.complete && !k.uploading) { 273 k.uploading = true; 274 d.uploads.current++; 275 d.uploads.attempted++; 276 xhr = k.xhr = new XMLHttpRequest(); 277 if (typeof FormData === "function" || typeof FormData === "object") { 278 var m = new FormData(); 279 try { 280 m.append(f.fileObjName, /android/i.test(navigator.userAgent) ? k.slice(0, k.size, k.type) : k, k.name); 281 } catch (uploadifiveErr) { 282 m.append(f.fileObjName, k); 283 } 284 for (i in f.formData) {
285 m.append(i, f.formData[i]); 286 } 287 xhr.open(f.method, f.uploadScript, true); 288 xhr.upload.addEventListener("progress", function (n) { 289 if (n.lengthComputable) { 290 d.progress(n, k); 291 } 292 }, false); 293 xhr.addEventListener("load", function (n) { 294 if (this.readyState == 4) { 295 k.uploading = false; 296 if (this.status == 200) { 297 if (k.xhr.responseText !== "Invalid file type.") { 298 d.uploadComplete(n, k, l); 299 } else { 300 d.error(k.xhr.responseText, k, l); 301 } 302 } else { 303 if (this.status == 404) { 304 d.error("404_FILE_NOT_FOUND", k, l); 305 } else { 306 if (this.status == 403) { 307 d.error("403_FORBIDDEN", k, l); 308 } else { 309 d.error("Unknown Error", k, l); 310 } 311 } 312 } 313 } 314 }); 315 xhr.send(m); 316 } else { 317 var j = new FileReader(); 318 j.onload = function (q) { 319 var t = "-------------------------" + (new Date).getTime(), p = "--", o = "\r\n", 320 s = ""; 321 s += p + t + o; 322 s += 'Content-Disposition: form-data; name="' + f.fileObjName + '"'; 323 if (k.name) { 324 s += '; filename="' + k.name + '"'; 325 } 326 s += o; 327 s += "Content-Type: application/octet-stream" + o + o; 328 s += q.target.result + o; 329 for (key in f.formData) { 330 s += p + t + o; 331 s += 'Content-Disposition: form-data; name="' + key + '"' + o + o; 332 s += f.formData[key] + o; 333 } 334 s += p + t + p + o; 335 xhr.upload.addEventListener("progress", function (u) { 336 d.progress(u, k); 337 }, false); 338 xhr.addEventListener("load", function (v) { 339 k.uploading = false; 340 var u = this.status; 341 if (u == 404) { 342 d.error("404_FILE_NOT_FOUND", k, l); 343 } else { 344 if (k.xhr.responseText != "Invalid file type.") { 345 d.uploadComplete(v, k, l); 346 } else { 347 d.error(k.xhr.responseText, k, l); 348 } 349 } 350 }, false); 351 var n = f.uploadScript; 352 if (f.method == "get") { 353 var r = b(f.formData).param(); 354 n += r; 355 } 356 xhr.open(f.method, f.uploadScript, true); 357 xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + t); 358 if (typeof f.onUploadFile === "function") { 359 f.onUploadFile.call(g, k); 360 } 361 xhr.sendAsBinary(s); 362 }; 363 j.readAsBinaryString(k); 364 } 365 } 366 }; 367 d.progress = function (l, j) { 368 if (b.inArray("onProgress", f.overrideEvents) < 0) { 369 if (l.lengthComputable) { 370 var k = Math.round((l.loaded / l.total) * 100); 371 } 372 j.queueItem.find(".fileinfo").html(" - " + k + "%"); 373 j.queueItem.find(".progress-bar").css("width", k + "%"); 374 } 375 if (typeof f.onProgress === "function") { 376 f.onProgress.call(g, j, l); 377 } 378 }; 379 d.error = function (l, j, k) { 380 if (b.inArray("onError", f.overrideEvents) < 0) { 381 switch (l) { 382 case"404_FILE_NOT_FOUND": 383 errorMsg = "404 Error"; 384 break; 385 case"403_FORBIDDEN": 386 errorMsg = "403 Forbidden"; 387 break; 388 case"FORBIDDEN_FILE_TYPE": 389 errorMsg = "Forbidden File Type"; 390 break; 391 case"FILE_SIZE_LIMIT_EXCEEDED": 392 errorMsg = "File Too Large"; 393 break; 394 default: 395 errorMsg = "Unknown Error"; 396 break; 397 } 398 if (typeof Yii != 'undefined') { 399 errorMsg = Yii.t('common', errorMsg); 400 } 401 j.queueItem.addClass("error").find(".fileinfo").html(" - " + errorMsg); 402 j.queueItem.find(".progress").remove(); 403 } 404 if (typeof f.onError === "function") { 405 f.onError.call(g, l, j); 406 } 407 j.skip = true; 408 if (l == "404_FILE_NOT_FOUND") { 409 d.uploads.errors++; 410 } else { 411 d.queue.errors++; 412 } 413 if (k) { 414 a.upload.call(g, null, true); 415 } 416 }; 417 d.uploadComplete = function (l, j, k) { 418 if (b.inArray("onUploadComplete", f.overrideEvents) < 0) { 419 j.queueItem.find(".progress-bar").css("width", "100%"); 420 j.queueItem.find(".fileinfo").html(" - Completed");
421 j.queueItem.find(".progress").slideUp(250); 422 j.queueItem.addClass("complete"); 423 } 424 if (typeof f.onUploadComplete === "function") { 425 f.onUploadComplete.call(g, j, j.xhr.responseText); 426 } 427 if (f.removeCompleted) { 428 setTimeout(function () { 429 a.cancel.call(g, j); 430 }, 3000); 431 } 432 j.complete = true; 433 d.uploads.successful++; 434 d.uploads.count++; 435 d.uploads.current--; 436 delete j.xhr; 437 if (k) { 438 a.upload.call(g, null, true); 439 } 440 }; 441 d.queueComplete = function () { 442 if (typeof f.onQueueComplete === "function") { 443 f.onQueueComplete.call(g, d.uploads); 444 } 445 }; 446 if (window.File && window.FileList && window.Blob && (window.FileReader || window.FormData)) { 447 f.id = "uploadifive-" + g.attr("id"); 448 d.button = b('<div id="' + f.id + '" class="uploadifive-button">' + f.buttonText + "</div>"); 449 if (f.buttonClass) { 450 d.button.addClass(f.buttonClass); 451 } 452 d.button.css({ 453 height: f.height, 454 "line-height": f.height + "px", 455 overflow: "hidden", 456 position: "relative", 457 "text-align": "center", 458 width: f.width 459 }); 460 g.before(d.button).appendTo(d.button).hide(); 461 d.createInput.call(g); 462 if (!f.queueID) { 463 f.queueID = f.id + "-queue"; 464 d.queueEl = b('<div id="' + f.queueID + '" class="uploadifive-queue" />'); 465 d.button.after(d.queueEl); 466 } else { 467 d.queueEl = b("#" + f.queueID); 468 } 469 if (f.dnd) { 470 var h = f.dropTarget ? b(f.dropTarget) : d.queueEl.get(0); 471 h.addEventListener("dragleave", function (j) { 472 j.preventDefault(); 473 j.stopPropagation(); 474 }, false); 475 h.addEventListener("dragenter", function (j) { 476 j.preventDefault(); 477 j.stopPropagation(); 478 }, false); 479 h.addEventListener("dragover", function (j) { 480 j.preventDefault(); 481 j.stopPropagation(); 482 }, false); 483 h.addEventListener("drop", d.drop, false); 484 } 485 if (!XMLHttpRequest.prototype.sendAsBinary) { 486 XMLHttpRequest.prototype.sendAsBinary = function (k) { 487 function l(n) { 488 return n.charCodeAt(0) & 255; 489 } 490 491 var m = Array.prototype.map.call(k, l); 492 var j = new Uint8Array(m); 493 this.send(j.buffer); 494 }; 495 } 496 if (typeof f.onInit === "function") { 497 f.onInit.call(g); 498 } 499 } else { 500 if (typeof f.onFallback === "function") { 501 f.onFallback.call(g); 502 } 503 return false; 504 } 505 }); 506 }, debug: function () { 507 return this.each(function () { 508 console.log(b(this).data("uploadifive")); 509 }); 510 }, clearQueue: function () { 511 this.each(function () { 512 var f = b(this), c = f.data("uploadifive"), e = c.settings; 513 for (var d in c.inputs) { 514 input = c.inputs[d]; 515 limit = input.files.length; 516 for (i = 0; i < limit; i++) { 517 file = input.files[i]; 518 a.cancel.call(f, file); 519 } 520 } 521 if (typeof e.onClearQueue === "function") { 522 e.onClearQueue.call(f, b("#" + c.settings.queueID)); 523 } 524 }); 525 }, cancel: function (d, c) { 526 this.each(function () { 527 var g = b(this), e = g.data("uploadifive"), f = e.settings; 528 if (typeof d === "string") { 529 if (!isNaN(d)) { 530 fileID = "uploadifive-" + b(this).attr("id") + "-file-" + d; 531 } 532 d = b("#" + fileID).data("file"); 533 } 534 d.skip = true; 535 e.filesCancelled++; 536 if (d.uploading) { 537 e.uploads.current--; 538 d.uploading = false; 539 d.xhr.abort(); 540 delete d.xhr; 541 a.upload.call(g); 542 } 543 if (b.inArray("onCancel", f.overrideEvents) < 0) { 544 e.removeQueueItem(d, c); 545 } 546 if (typeof f.onCancel === "function") { 547 f.onCancel.call(g, d); 548 } 549 }); 550 }, upload: function (c, d) { 551 this.each(function () { 552 var h = b(this), e = h.data("uploadifive"), f = e.settings; 553 if (c) { 554 e.uploadFile.call(h, c); 555 } else { 556 if ((e.uploads.count + e.uploads.current) < f.uploadLimit || f.uploadLimit == 0) { 557 if (!d) { 558 e.uploads.attempted = 0; 559 e.uploads.successsful = 0; 560 e.uploads.errors = 0; 561 var g = e.filesToUpload(); 562 if (typeof f.onUpload === "function") { 563 f.onUpload.call(h, g, f); 564 } 565 } 566 b("#" + f.queueID).find(".uploadifive-queue-item").not(".error, .complete").each(function () { 567 _file = b(this).data("file"); 568 if ((e.uploads.current >= f.simUploadLimit && f.simUploadLimit !== 0) || (e.uploads.current >= f.uploadLimit && f.uploadLimit !== 0) || (e.uploads.count >= f.uploadLimit && f.uploadLimit !== 0)) { 569 return false;
570 } 571 if (f.checkScript) { 572 _file.checking = true; 573 skipFile = e.checkExists(_file); 574 _file.checking = false; 575 if (!skipFile) { 576 e.uploadFile(_file, true); 577 } 578 } else { 579 e.uploadFile(_file, true); 580 } 581 }); 582 if (b("#" + f.queueID).find(".uploadifive-queue-item").not(".error, .complete").size() == 0) { 583 e.queueComplete(); 584 } 585 } else { 586 if (e.uploads.current == 0) { 587 if (b.inArray("onError", f.overrideEvents) < 0) { 588 if (e.filesToUpload() > 0 && f.uploadLimit != 0) { 589 alert("The maximum upload limit has been reached."); 590 } 591 } 592 if (typeof f.onError === "function") { 593 f.onError.call(h, "UPLOAD_LIMIT_EXCEEDED", e.filesToUpload()); 594 } 595 } 596 } 597 } 598 }); 599 }, destroy: function () { 600 this.each(function () { 601 var e = b(this), c = e.data("uploadifive"), d = c.settings; 602 a.clearQueue.call(e); 603 if (!d.queueID) { 604 b("#" + d.queueID).remove(); 605 } 606 e.siblings("input").remove(); 607 e.show().insertBefore(c.button); 608 c.button.remove(); 609 if (typeof d.onDestroy === "function") { 610 d.onDestroy.call(e); 611 } 612 }); 613 } 614 }; 615 b.fn.uploadifive = function (c) { 616 if (a[c]) { 617 return a[c].apply(this, Array.prototype.slice.call(arguments, 1)); 618 } else { 619 if (typeof c === "object" || !c) { 620 return a.init.apply(this, arguments); 621 } else { 622 b.error("The method " + c + " does not exist in $.uploadify"); 623 } 624 } 625 }; 626})(jQuery);
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.