Implement drag-and-drop support in the viewer for local files

This commit is contained in:
Dimitris Kountanis 2018-06-10 15:39:06 +02:00 committed by Tim van der Meij
parent db874b6680
commit 8e95506116
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

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');