Skip to content

Commit

Permalink
Disable file dropping
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Jul 3, 2024
1 parent 68d529d commit 7e5dddb
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,49 +659,49 @@ const PDFViewerApplication = {
file = AppOptions.get("defaultUrl");
}

if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
const fileInput = (this._openFileInput = document.createElement("input"));
fileInput.id = "fileInput";
fileInput.hidden = true;
fileInput.type = "file";
fileInput.value = null;
document.body.append(fileInput);

fileInput.addEventListener("change", function (evt) {
const { files } = evt.target;
if (!files || files.length === 0) {
return;
}
eventBus.dispatch("fileinputchange", {
source: this,
fileInput: evt.target,
});
});

// Enable dragging-and-dropping a new PDF file onto the viewerContainer.
appConfig.mainContainer.addEventListener("dragover", function (evt) {
for (const item of evt.dataTransfer.items) {
if (item.type === "application/pdf") {
evt.dataTransfer.dropEffect =
evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
evt.preventDefault();
evt.stopPropagation();
return;
}
}
});
appConfig.mainContainer.addEventListener("drop", function (evt) {
if (evt.dataTransfer.files?.[0].type !== "application/pdf") {
return;
}
evt.preventDefault();
evt.stopPropagation();
eventBus.dispatch("fileinputchange", {
source: this,
fileInput: evt.dataTransfer,
});
});
}
// if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
// const fileInput = (this._openFileInput = document.createElement("input"));
// fileInput.id = "fileInput";
// fileInput.hidden = true;
// fileInput.type = "file";
// fileInput.value = null;
// document.body.append(fileInput);
//
// fileInput.addEventListener("change", function (evt) {
// const { files } = evt.target;
// if (!files || files.length === 0) {
// return;
// }
// eventBus.dispatch("fileinputchange", {
// source: this,
// fileInput: evt.target,
// });
// });
//
// // Enable dragging-and-dropping a new PDF file onto the viewerContainer.
// appConfig.mainContainer.addEventListener("dragover", function (evt) {
// for (const item of evt.dataTransfer.items) {
// if (item.type === "application/pdf") {
// evt.dataTransfer.dropEffect =
// evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
// evt.preventDefault();
// evt.stopPropagation();
// return;
// }
// }
// });
// appConfig.mainContainer.addEventListener("drop", function (evt) {
// if (evt.dataTransfer.files?.[0].type !== "application/pdf") {
// return;
// }
// evt.preventDefault();
// evt.stopPropagation();
// eventBus.dispatch("fileinputchange", {
// source: this,
// fileInput: evt.dataTransfer,
// });
// });
// }

if (!AppOptions.get("supportsDocumentFonts")) {
AppOptions.set("disableFontFace", true);
Expand Down

0 comments on commit 7e5dddb

Please sign in to comment.