|
1 | 1 | /*
|
2 |
| - * jQuery File Upload Plugin 5.21 |
| 2 | + * jQuery File Upload Plugin 5.21.3 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2010, Sebastian Tschan
|
|
33 | 33 | $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader);
|
34 | 34 | $.support.xhrFormDataFileUpload = !!window.FormData;
|
35 | 35 |
|
36 |
| - // The form.elements propHook is added to filter serialized elements |
37 |
| - // to not include file inputs in jQuery 1.9.0. |
38 |
| - // This hooks directly into jQuery.fn.serializeArray. |
39 |
| - // For more info, see http://bugs.jquery.com/ticket/13306 |
40 |
| - $.propHooks.elements = { |
41 |
| - get: function (form) { |
42 |
| - if ($.nodeName(form, 'form')) { |
43 |
| - return $.grep(form.elements, function (elem) { |
44 |
| - return !$.nodeName(elem, 'input') || elem.type !== 'file'; |
45 |
| - }); |
46 |
| - } |
47 |
| - return null; |
48 |
| - } |
49 |
| - }; |
50 |
| - |
51 | 36 | // The fileupload widget listens for change events on file input fields defined
|
52 | 37 | // via fileInput setting and paste or drop events of the given dropZone.
|
53 | 38 | // In addition to the default jQuery Widget methods, the fileupload widget
|
|
241 | 226 | _isXHRUpload: function (options) {
|
242 | 227 | return !options.forceIframeTransport &&
|
243 | 228 | ((!options.multipart && $.support.xhrFileUpload) ||
|
244 |
| - $.support.xhrFormDataFileUpload); |
| 229 | + $.support.xhrFormDataFileUpload); |
245 | 230 | },
|
246 | 231 |
|
247 | 232 | _getFormData: function (options) {
|
|
276 | 261 | total,
|
277 | 262 | loaded;
|
278 | 263 | if (data._time && data.progressInterval &&
|
279 |
| - (now - data._time < data.progressInterval) && |
280 |
| - e.loaded !== e.total) { |
| 264 | + (now - data._time < data.progressInterval) && |
| 265 | + e.loaded !== e.total) { |
281 | 266 | return;
|
282 | 267 | }
|
283 | 268 | data._time = now;
|
|
337 | 322 | _initXHRData: function (options) {
|
338 | 323 | var formData,
|
339 | 324 | file = options.files[0],
|
340 |
| - // Ignore non-multipart setting if not supported: |
| 325 | + // Ignore non-multipart setting if not supported: |
341 | 326 | multipart = options.multipart || !$.support.xhrFileUpload,
|
342 | 327 | paramName = options.paramName[0];
|
343 | 328 | options.headers = options.headers || {};
|
|
389 | 374 | // This check allows the tests to run with
|
390 | 375 | // dummy objects:
|
391 | 376 | if ((window.Blob && file instanceof Blob) ||
|
392 |
| - (window.File && file instanceof File)) { |
| 377 | + (window.File && file instanceof File)) { |
393 | 378 | formData.append(
|
394 | 379 | options.paramName[index] || paramName,
|
395 | 380 | file,
|
|
412 | 397 | options.formData = this._getFormData(options);
|
413 | 398 | // Add redirect url to form data on cross-domain uploads:
|
414 | 399 | if (options.redirect && $('<a></a>').prop('href', options.url)
|
415 |
| - .prop('host') !== location.host) { |
| 400 | + .prop('host') !== location.host) { |
416 | 401 | options.formData.push({
|
417 | 402 | name: options.redirectParamName || 'redirect',
|
418 | 403 | value: options.redirect
|
|
480 | 465 | options.type = (options.type || options.form.prop('method') || '')
|
481 | 466 | .toUpperCase();
|
482 | 467 | if (options.type !== 'POST' && options.type !== 'PUT' &&
|
483 |
| - options.type !== 'PATCH') { |
| 468 | + options.type !== 'PATCH') { |
484 | 469 | options.type = 'POST';
|
485 | 470 | }
|
486 | 471 | if (!options.formAcceptCharset) {
|
|
546 | 531 | jqXHR,
|
547 | 532 | upload;
|
548 | 533 | if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) ||
|
549 |
| - options.data) { |
| 534 | + options.data) { |
550 | 535 | return false;
|
551 | 536 | }
|
552 | 537 | if (testOnly) {
|
|
561 | 546 | );
|
562 | 547 | }
|
563 | 548 | // The chunk upload method:
|
564 |
| - upload = function (i) { |
| 549 | + upload = function () { |
565 | 550 | // Clone the options object for each chunk upload:
|
566 | 551 | var o = $.extend({}, options);
|
567 | 552 | o.blob = slice.call(
|
|
581 | 566 | // Add progress listeners for this chunk upload:
|
582 | 567 | that._initProgressListener(o);
|
583 | 568 | jqXHR = ((that._trigger('chunksend', null, o) !== false && $.ajax(o)) ||
|
584 |
| - that._getXHRPromise(false, o.context)) |
| 569 | + that._getXHRPromise(false, o.context)) |
585 | 570 | .done(function (result, textStatus, jqXHR) {
|
586 | 571 | ub = that._getUploadedBytes(jqXHR) ||
|
587 | 572 | (ub + o.chunkSize);
|
|
648 | 633 | },
|
649 | 634 |
|
650 | 635 | _onDone: function (result, textStatus, jqXHR, options) {
|
651 |
| - if (!this._isXHRUpload(options) || !options.loaded || |
652 |
| - options.loaded < options.total) { |
| 636 | + if (!options.uploadedBytes && (!this._isXHRUpload(options) || |
| 637 | + !options.loaded || options.loaded < options.total)) { |
653 | 638 | var total = this._getTotal(options.files) || 1;
|
654 | 639 | // Create a progress event for each iframe load,
|
655 | 640 | // or if there has been no progress event with
|
|
707 | 692 | options._bitrateTimer = new that._BitrateTimer();
|
708 | 693 | jqXHR = jqXHR || (
|
709 | 694 | ((aborted || that._trigger('send', e, options) === false) &&
|
710 |
| - that._getXHRPromise(false, options.context, aborted)) || |
711 |
| - that._chunkedUpload(options) || $.ajax(options) |
712 |
| - ).done(function (result, textStatus, jqXHR) { |
713 |
| - that._onDone(result, textStatus, jqXHR, options); |
714 |
| - }).fail(function (jqXHR, textStatus, errorThrown) { |
715 |
| - that._onFail(jqXHR, textStatus, errorThrown, options); |
716 |
| - }).always(function (jqXHRorResult, textStatus, jqXHRorError) { |
717 |
| - that._sending -= 1; |
718 |
| - that._onAlways( |
719 |
| - jqXHRorResult, |
720 |
| - textStatus, |
721 |
| - jqXHRorError, |
722 |
| - options |
723 |
| - ); |
724 |
| - if (options.limitConcurrentUploads && |
| 695 | + that._getXHRPromise(false, options.context, aborted)) || |
| 696 | + that._chunkedUpload(options) || $.ajax(options) |
| 697 | + ).done(function (result, textStatus, jqXHR) { |
| 698 | + that._onDone(result, textStatus, jqXHR, options); |
| 699 | + }).fail(function (jqXHR, textStatus, errorThrown) { |
| 700 | + that._onFail(jqXHR, textStatus, errorThrown, options); |
| 701 | + }).always(function (jqXHRorResult, textStatus, jqXHRorError) { |
| 702 | + that._sending -= 1; |
| 703 | + that._onAlways( |
| 704 | + jqXHRorResult, |
| 705 | + textStatus, |
| 706 | + jqXHRorError, |
| 707 | + options |
| 708 | + ); |
| 709 | + if (options.limitConcurrentUploads && |
725 | 710 | options.limitConcurrentUploads > that._sending) {
|
726 |
| - // Start the next queued upload, |
727 |
| - // that has not been aborted: |
728 |
| - var nextSlot = that._slots.shift(), |
729 |
| - isPending; |
730 |
| - while (nextSlot) { |
731 |
| - // jQuery 1.6 doesn't provide .state(), |
732 |
| - // while jQuery 1.8+ removed .isRejected(): |
733 |
| - isPending = nextSlot.state ? |
| 711 | + // Start the next queued upload, |
| 712 | + // that has not been aborted: |
| 713 | + var nextSlot = that._slots.shift(), |
| 714 | + isPending; |
| 715 | + while (nextSlot) { |
| 716 | + // jQuery 1.6 doesn't provide .state(), |
| 717 | + // while jQuery 1.8+ removed .isRejected(): |
| 718 | + isPending = nextSlot.state ? |
734 | 719 | nextSlot.state() === 'pending' :
|
735 | 720 | !nextSlot.isRejected();
|
736 |
| - if (isPending) { |
737 |
| - nextSlot.resolve(); |
738 |
| - break; |
| 721 | + if (isPending) { |
| 722 | + nextSlot.resolve(); |
| 723 | + break; |
| 724 | + } |
| 725 | + nextSlot = that._slots.shift(); |
739 | 726 | }
|
740 |
| - nextSlot = that._slots.shift(); |
741 | 727 | }
|
742 |
| - } |
743 |
| - }); |
| 728 | + }); |
744 | 729 | return jqXHR;
|
745 | 730 | };
|
746 | 731 | this._beforeSend(e, options);
|
747 | 732 | if (this.options.sequentialUploads ||
|
748 |
| - (this.options.limitConcurrentUploads && |
| 733 | + (this.options.limitConcurrentUploads && |
749 | 734 | this.options.limitConcurrentUploads <= this._sending)) {
|
750 | 735 | if (this.options.limitConcurrentUploads > 1) {
|
751 | 736 | slot = $.Deferred();
|
|
783 | 768 | fileSet,
|
784 | 769 | i;
|
785 | 770 | if (!(options.singleFileUploads || limit) ||
|
786 |
| - !this._isXHRUpload(options)) { |
| 771 | + !this._isXHRUpload(options)) { |
787 | 772 | fileSet = [data.files];
|
788 | 773 | paramNameSet = [paramName];
|
789 | 774 | } else if (!options.singleFileUploads && limit) {
|
|
808 | 793 | newData.submit = function () {
|
809 | 794 | newData.jqXHR = this.jqXHR =
|
810 | 795 | (that._trigger('submit', e, this) !== false) &&
|
811 |
| - that._onSend(e, this); |
| 796 | + that._onSend(e, this); |
812 | 797 | return this.jqXHR;
|
813 | 798 | };
|
814 | 799 | result = that._trigger('add', e, newData);
|
|
871 | 856 | dirReader = entry.createReader();
|
872 | 857 | dirReader.readEntries(function (entries) {
|
873 | 858 | that._handleFileTreeEntries(
|
874 |
| - entries, |
875 |
| - path + entry.name + '/' |
876 |
| - ).done(function (files) { |
877 |
| - dfd.resolve(files); |
878 |
| - }).fail(errorHandler); |
| 859 | + entries, |
| 860 | + path + entry.name + '/' |
| 861 | + ).done(function (files) { |
| 862 | + dfd.resolve(files); |
| 863 | + }).fail(errorHandler); |
879 | 864 | }, errorHandler);
|
880 | 865 | } else {
|
881 | 866 | // Return an empy list for file system items
|
|
888 | 873 | _handleFileTreeEntries: function (entries, path) {
|
889 | 874 | var that = this;
|
890 | 875 | return $.when.apply(
|
891 |
| - $, |
892 |
| - $.map(entries, function (entry) { |
893 |
| - return that._handleFileTreeEntry(entry, path); |
894 |
| - }) |
895 |
| - ).pipe(function () { |
896 |
| - return Array.prototype.concat.apply( |
897 |
| - [], |
898 |
| - arguments |
899 |
| - ); |
900 |
| - }); |
| 876 | + $, |
| 877 | + $.map(entries, function (entry) { |
| 878 | + return that._handleFileTreeEntry(entry, path); |
| 879 | + }) |
| 880 | + ).pipe(function () { |
| 881 | + return Array.prototype.concat.apply( |
| 882 | + [], |
| 883 | + arguments |
| 884 | + ); |
| 885 | + }); |
901 | 886 | },
|
902 | 887 |
|
903 | 888 | _getDroppedFiles: function (dataTransfer) {
|
904 | 889 | dataTransfer = dataTransfer || {};
|
905 | 890 | var items = dataTransfer.items;
|
906 | 891 | if (items && items.length && (items[0].webkitGetAsEntry ||
|
907 |
| - items[0].getAsEntry)) { |
| 892 | + items[0].getAsEntry)) { |
908 | 893 | return this._handleFileTreeEntries(
|
909 | 894 | $.map(items, function (item) {
|
910 | 895 | var entry;
|
|
959 | 944 | return this._getSingleFileInputFiles(fileInput);
|
960 | 945 | }
|
961 | 946 | return $.when.apply(
|
962 |
| - $, |
963 |
| - $.map(fileInput, this._getSingleFileInputFiles) |
964 |
| - ).pipe(function () { |
965 |
| - return Array.prototype.concat.apply( |
966 |
| - [], |
967 |
| - arguments |
968 |
| - ); |
969 |
| - }); |
| 947 | + $, |
| 948 | + $.map(fileInput, this._getSingleFileInputFiles) |
| 949 | + ).pipe(function () { |
| 950 | + return Array.prototype.concat.apply( |
| 951 | + [], |
| 952 | + arguments |
| 953 | + ); |
| 954 | + }); |
970 | 955 | },
|
971 | 956 |
|
972 | 957 | _onChange: function (e) {
|
|
997 | 982 | }
|
998 | 983 | });
|
999 | 984 | if (this._trigger('paste', e, data) === false ||
|
1000 |
| - this._onAdd(e, data) === false) { |
| 985 | + this._onAdd(e, data) === false) { |
1001 | 986 | return false;
|
1002 | 987 | }
|
1003 | 988 | },
|
|
1065 | 1050 | var options = this.options;
|
1066 | 1051 | if (options.fileInput === undefined) {
|
1067 | 1052 | options.fileInput = this.element.is('input[type="file"]') ?
|
1068 |
| - this.element : this.element.find('input[type="file"]'); |
| 1053 | + this.element : this.element.find('input[type="file"]'); |
1069 | 1054 | } else if (!(options.fileInput instanceof $)) {
|
1070 | 1055 | options.fileInput = $(options.fileInput);
|
1071 | 1056 | }
|
|
0 commit comments