From 8e9550611696cf33172a864c934b6f58996356a6 Mon Sep 17 00:00:00 2001 From: Dimitris Kountanis Date: Sun, 10 Jun 2018 15:39:06 +0200 Subject: [PATCH] Implement drag-and-drop support in the viewer for local files --- web/app.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/web/app.js b/web/app.js index b9f3f1d62..57b1d82fd 100644 --- a/web/app.js +++ b/web/app.js @@ -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');