mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
Fix: prevent fileInput.js from adding event listeners more than once (#2365)
Fix fileInput.js adding event listeners more than once - Fix a bug that caused fileInput.js to add event listeners more than once per HTML file as it's included in fileSelector fragment in fragments/common.html thus it's being loaded N times where N is the number of file selectors / custom file chooser / file input elements per HTML file, which resulted in each event actions being executed N times as well, which was prevalent in drag and drop operations such as dragging and dropping a file called y.png, it would be duplicated N times (as in /sign path).
This commit is contained in:
parent
db02fba31f
commit
04ccdf6f76
@ -1,6 +1,10 @@
|
|||||||
document.addEventListener("DOMContentLoaded", function () {
|
let isScriptExecuted = false;
|
||||||
document.querySelectorAll(".custom-file-chooser").forEach(setupFileInput);
|
if (!isScriptExecuted) {
|
||||||
});
|
isScriptExecuted = true;
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
document.querySelectorAll(".custom-file-chooser").forEach(setupFileInput);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function setupFileInput(chooser) {
|
function setupFileInput(chooser) {
|
||||||
const elementId = chooser.getAttribute("data-bs-element-id");
|
const elementId = chooser.getAttribute("data-bs-element-id");
|
||||||
@ -85,7 +89,7 @@ function setupFileInput(chooser) {
|
|||||||
$("#" + elementId).on("change", function (e) {
|
$("#" + elementId).on("change", function (e) {
|
||||||
let element = e.target;
|
let element = e.target;
|
||||||
const isDragAndDrop = e.detail?.source == 'drag-drop';
|
const isDragAndDrop = e.detail?.source == 'drag-drop';
|
||||||
|
|
||||||
if (element instanceof HTMLInputElement && element.hasAttribute("multiple")) {
|
if (element instanceof HTMLInputElement && element.hasAttribute("multiple")) {
|
||||||
allFiles = isDragAndDrop ? allFiles : [... allFiles, ... element.files];
|
allFiles = isDragAndDrop ? allFiles : [... allFiles, ... element.files];
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user