1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-11-11 02:10:11 +01:00

Made it possible to add files via the selector "File by File".

This commit is contained in:
ge64qev 2024-05-06 11:18:59 +02:00
parent f7aebf22c8
commit 7ba0067688
2 changed files with 19 additions and 7 deletions

View File

@ -47,12 +47,11 @@ function setupFileInput(chooser) {
const dt = e.dataTransfer;
const files = dt.files;
for (let i = 0; i < files.length; i++) {
allFiles.push(files[i]);
}
//Do not Update allFiles array here to prevent duplication, the change event listener will take care of that
const dataTransfer = new DataTransfer();
allFiles.forEach((file) => dataTransfer.items.add(file));
for (let i = 0; i < files.length; i++) {
dataTransfer.items.add(files[i]);
}
const fileInput = document.getElementById(elementId);
fileInput.files = dataTransfer.files;
@ -81,8 +80,21 @@ function setupFileInput(chooser) {
document.body.addEventListener("drop", dropListener);
$("#" + elementId).on("change", function (e) {
allFiles = Array.from(e.target.files);
//Get newly Added Files
const newFiles = Array.from(e.target.files);
//Add Files to existing Files
allFiles = allFiles.concat(newFiles);
//Update the file inout`s files property
const dataTransfer = new DataTransfer();
allFiles.forEach((file) => dataTransfer.items.add(file));
e.target.files = dataTransfer.files;
handleFileInputChange(this);
//Call the displayFiles function with the allFiles array
displayFiles(allFiles)
});
function handleFileInputChange(inputElement) {

View File

@ -9,7 +9,7 @@ document.getElementById("fileInput-input").addEventListener("change", function (
});
/**
* @param {FileList} files
* @param {File[]} files
*/
function displayFiles(files) {
const list = document.getElementById("selectedFiles");