Convert native for loop to Array forEach()

This fixes a problem with variable scoping and closures.

Closes gh-3473
This commit is contained in:
Thomas Kluyver 2018-03-28 14:58:22 +02:00
parent faa0cab302
commit 9e72e054c0

View File

@ -254,8 +254,7 @@ define([
var files;
if(dropOrForm === 'drop'){
files = event.originalEvent.dataTransfer.files;
} else
{
} else {
files = event.originalEvent.target.files;
}
@ -275,12 +274,11 @@ define([
});
};
for (var i = 0; i < files.length; i++) {
var f = files[i];
Array.from(files).forEach(function(f) {
var name_and_ext = utils.splitext(f.name);
var file_ext = name_and_ext[1];
if (f.size > this._max_upload_size_mb * 1024 * 1024) {
if (f.size > that._max_upload_size_mb * 1024 * 1024) {
var body_msg = i18n.msg.sprintf(i18n.msg._("The file size is %d MB. Do you still want to upload it?"),
Math.round(f.size / (1024 * 1024)));
dialog.modal({
@ -314,7 +312,7 @@ define([
reader.onload = reader_onload;
reader.onerror = reader_onerror;
}
}
});
// Replace the file input form wth a clone of itself. This is required to
// reset the form. Otherwise, if you upload a file, delete it and try to
// upload it again, the changed event won't fire.