Skip to content

Commit 522dde2

Browse files
committed
refactor(tpl/upload): extract files param
1 parent 98f4320 commit 522dde2

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/tpl/asset/main.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,8 @@
570570
}
571571
}
572572

573-
function uploadProgressively() {
574-
var files = Array.prototype.slice.call(fileInput.files);
575-
if (!files.length) {
573+
function uploadProgressively(files) {
574+
if (!files || !files.length) {
576575
return;
577576
}
578577

@@ -605,10 +604,14 @@
605604
e.stopPropagation();
606605
e.preventDefault();
607606

608-
uploadProgressively();
607+
var files = Array.prototype.slice.call(fileInput.files);
608+
uploadProgressively(files);
609609
});
610610

611-
fileInput.addEventListener('change', uploadProgressively);
611+
fileInput.addEventListener('change', function () {
612+
var files = Array.prototype.slice.call(fileInput.files);
613+
uploadProgressively(files);
614+
});
612615
return uploadProgressively;
613616
}
614617

@@ -652,7 +655,8 @@
652655

653656
fileInput.files = e.dataTransfer.files;
654657
if (uploadProgressively) {
655-
uploadProgressively();
658+
var files = Array.prototype.slice.call(e.dataTransfer.files);
659+
uploadProgressively(files);
656660
} else {
657661
form.submit();
658662
}

src/tpl/asset/main.js.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,8 @@ var percent = 100 * e.loaded / e.total;
504504
elProgress.style.width = percent + '%';
505505
}
506506
}
507-
function uploadProgressively() {
508-
var files = Array.prototype.slice.call(fileInput.files);
509-
if (!files.length) {
507+
function uploadProgressively(files) {
508+
if (!files || !files.length) {
510509
return;
511510
}
512511
var formName = fileInput.name;
@@ -534,9 +533,13 @@ btnSubmit.disabled = true;
534533
form.addEventListener('submit', function (e) {
535534
e.stopPropagation();
536535
e.preventDefault();
537-
uploadProgressively();
536+
var files = Array.prototype.slice.call(fileInput.files);
537+
uploadProgressively(files);
538+
});
539+
fileInput.addEventListener('change', function () {
540+
var files = Array.prototype.slice.call(fileInput.files);
541+
uploadProgressively(files);
538542
});
539-
fileInput.addEventListener('change', uploadProgressively);
540543
return uploadProgressively;
541544
}
542545
function enableAddDragDrop(uploadProgressively) {
@@ -573,7 +576,8 @@ optFile.click();
573576
}
574577
fileInput.files = e.dataTransfer.files;
575578
if (uploadProgressively) {
576-
uploadProgressively();
579+
var files = Array.prototype.slice.call(e.dataTransfer.files);
580+
uploadProgressively(files);
577581
} else {
578582
form.submit();
579583
}

0 commit comments

Comments
 (0)