|
433 | 433 | return; |
434 | 434 | } |
435 | 435 |
|
436 | | - var btnSubmit = form.querySelector('.submit') || form.querySelector('input[type=submit]'); |
437 | | - if (!btnSubmit) { |
438 | | - return; |
439 | | - } |
440 | | - |
441 | 436 | var uploadType = document.body.querySelector('.upload-type'); |
442 | 437 | if (!uploadType) { |
443 | 438 | return; |
444 | 439 | } |
445 | 440 |
|
446 | | - var classUploading = 'uploading'; |
447 | | - |
448 | 441 | var file = 'file'; |
449 | 442 | var dirFile = 'dirfile'; |
450 | 443 | var innerDirFile = 'innerdirfile'; |
|
462 | 455 | ele && ele.classList.remove(className); |
463 | 456 | } |
464 | 457 |
|
465 | | - function hasClass(ele, className) { |
466 | | - return ele && ele.classList.contains(className); |
467 | | - } |
468 | | - |
469 | 458 | var padStart = String.prototype.padStart ? function (sourceString, targetLength, padTemplate) { |
470 | 459 | return sourceString.padStart(targetLength, padTemplate); |
471 | 460 | } : function (sourceString, targetLength, padTemplate) { |
|
749 | 738 | return; |
750 | 739 | } |
751 | 740 |
|
752 | | - var elProgress = btnSubmit.querySelector('.progress'); |
| 741 | + var uploading = false; |
| 742 | + var batches = []; |
| 743 | + var elProgress = upload.querySelector('.progress'); |
753 | 744 |
|
754 | 745 | function onComplete() { |
755 | 746 | if (elProgress) { |
756 | 747 | elProgress.style.width = ''; |
757 | 748 | } |
758 | | - fileInput.disabled = false; |
759 | | - btnSubmit.disabled = false; |
760 | | - removeClass(upload, classUploading); |
| 749 | + if (batches.length) { |
| 750 | + uploadBatch(batches.shift()); |
| 751 | + } else { |
| 752 | + uploading = false; |
| 753 | + } |
761 | 754 | } |
762 | 755 |
|
763 | 756 | function onLoad() { |
764 | | - location.reload(); |
| 757 | + !uploading && location.reload(); |
765 | 758 | } |
766 | 759 |
|
767 | 760 | function onProgress(e) { |
|
776 | 769 | return; |
777 | 770 | } |
778 | 771 |
|
| 772 | + if (uploading) { |
| 773 | + batches.push(files); |
| 774 | + } else { |
| 775 | + uploading = true; |
| 776 | + uploadBatch(files); |
| 777 | + } |
| 778 | + } |
| 779 | + |
| 780 | + function uploadBatch(files) { |
779 | 781 | var formName = fileInput.name; |
780 | 782 | var parts = new FormData(); |
781 | 783 | files.forEach(function (file) { |
|
805 | 807 |
|
806 | 808 | xhr.open(form.method, form.action); |
807 | 809 | xhr.send(parts); |
808 | | - addClass(upload, classUploading); |
809 | | - fileInput.disabled = true; |
810 | | - btnSubmit.disabled = true; |
811 | 810 | } |
812 | 811 |
|
813 | 812 | return uploadProgressively; |
|
847 | 846 | e.stopPropagation(); |
848 | 847 | e.preventDefault(); |
849 | 848 | removeClass(e.currentTarget, classDragging); |
850 | | - if (hasClass(e.currentTarget, classUploading)) { |
851 | | - return; |
852 | | - } |
853 | 849 | fileInput.value = ''; |
854 | 850 |
|
855 | 851 | if (!e.dataTransfer || !e.dataTransfer.files || !e.dataTransfer.files.length) { |
|
862 | 858 | // must use progressive upload by JS if has directory |
863 | 859 | return; |
864 | 860 | } |
865 | | - btnSubmit.disabled = true; // disable earlier |
866 | 861 | var itemsCount = items.length; // save items count earlier, items will be lost after calling FileSystemFileEntry.file() |
867 | 862 | itemsToFiles(items, function (files) { |
868 | 863 | itemsCount > 1 ? switchToDirMode() : switchToAnyDirMode(); |
|
0 commit comments