diff options
-rw-r--r-- | css/viewer.css | 21 | ||||
-rw-r--r-- | js/previewplugin.js | 1 | ||||
-rw-r--r-- | js/workersrc.js | 25 |
3 files changed, 47 insertions, 0 deletions
diff --git a/css/viewer.css b/css/viewer.css index eca5f53..9d4594c 100644 --- a/css/viewer.css +++ b/css/viewer.css @@ -21,3 +21,24 @@ html .doorHangerRight:after { html .doorHangerRight:before { right: 53px!important; } + +/* Prevent printing from the browser when the download of a share is hidden. */ +@media print { + .pdfViewer.disabledTextSelection { + visibility: hidden; + display: none; + } +} + +/* Prevent text selection when the download of a share is hidden. */ +.pdfViewer.disabledTextSelection .textLayer { + user-select: none; + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; +} + +/* Override text cursor in descendants. */ +.pdfViewer.disabledTextSelection .textLayer * { + cursor: default; +} diff --git a/js/previewplugin.js b/js/previewplugin.js index ad3b338..5f7646d 100644 --- a/js/previewplugin.js +++ b/js/previewplugin.js @@ -97,6 +97,7 @@ var hideDownload = $('#hideDownload').val(); if (hideDownload === 'true') { iframe.find('.download').addClass('hidden'); + iframe.find('.pdfViewer').addClass('disabledTextSelection') } }); diff --git a/js/workersrc.js b/js/workersrc.js index 1c9b4f0..b9c8e2c 100644 --- a/js/workersrc.js +++ b/js/workersrc.js @@ -70,6 +70,31 @@ function initializeCustomPDFViewerApplication() { this.downloadManager.downloadUrl(url, getPDFFileNameFromURL(url)); }; + + var hideDownload = window.parent.document.getElementById('hideDownload').value === 'true'; + if (hideDownload) { + // Disable download function when downloads are hidden, as even if the + // buttons in the UI are hidden the download could still be triggered + // with Ctrl|Meta+S. + PDFViewerApplication.download = function() { + } + + // Disable printing service when downloads are hidden, as even if the + // buttons in the UI are hidden the printing could still be triggered + // with Ctrl|Meta+P. + // Abuse the "supportsPrinting" parameter, which signals that the + // browser does not fully support printing, to make PDFViewer disable + // the printing service. + // "supportsPrinting" is a getter function, so it needs to be deleted + // before replacing it with a simple value. + delete PDFViewerApplication.supportsPrinting; + PDFViewerApplication.supportsPrinting = false; + // When printing is not supported a warning is shown by the default + // "beforePrint" function when trying to print. That function needs to + // be replaced with an empty one to prevent that warning to be shown. + PDFViewerApplication.beforePrint = function() { + } + } } document.addEventListener('webviewerloaded', initializeCustomPDFViewerApplication, true); |