mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
[Editor] Support dragging & dropping images on a pdf (bug 1900907)
This commit is contained in:
parent
b557fba118
commit
412e03e576
2 changed files with 56 additions and 8 deletions
20
web/app.js
20
web/app.js
|
@ -670,18 +670,22 @@ const PDFViewerApplication = {
|
|||
|
||||
// Enable dragging-and-dropping a new PDF file onto the viewerContainer.
|
||||
appConfig.mainContainer.addEventListener("dragover", function (evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
evt.dataTransfer.dropEffect =
|
||||
evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
|
||||
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) {
|
||||
evt.preventDefault();
|
||||
|
||||
const { files } = evt.dataTransfer;
|
||||
if (!files || files.length === 0) {
|
||||
if (evt.dataTransfer.files?.[0].type !== "application/pdf") {
|
||||
return;
|
||||
}
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
eventBus.dispatch("fileinputchange", {
|
||||
source: this,
|
||||
fileInput: evt.dataTransfer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue