1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #9794 from timvandermeij/drag-and-drop

Implement drag-and-drop support in the viewer for local files
This commit is contained in:
Tim van der Meij 2018-06-10 16:04:54 +02:00 committed by GitHub
commit 98cabb388a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1622,6 +1622,24 @@ function webViewerInitialized() {
fileInput: evt.target,
});
});
// Enable draging-and-dropping a new PDF file onto the viewerContainer.
appConfig.mainContainer.addEventListener('dragover', function(evt) {
evt.preventDefault();
evt.dataTransfer.dropEffect = 'move';
});
appConfig.mainContainer.addEventListener('drop', function(evt) {
evt.preventDefault();
const files = evt.dataTransfer.files;
if (!files || files.length === 0) {
return;
}
PDFViewerApplication.eventBus.dispatch('fileinputchange', {
fileInput: evt.dataTransfer,
});
});
} else {
appConfig.toolbar.openFile.setAttribute('hidden', 'true');
appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');