From dda32c3a40dfa3075bfb4a3a204ac1a1cdaa2cb8 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 3 Sep 2019 18:46:12 +0300 Subject: [PATCH] feature(view) add support of pdf --- client/modules/view.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/client/modules/view.js b/client/modules/view.js index f254da0f..ab7b5890 100644 --- a/client/modules/view.js +++ b/client/modules/view.js @@ -123,9 +123,33 @@ async function show(data, options) { case 'media': return viewMedia(path); + + case 'pdf': + return viewPDF(path); } } +async function viewPDF(src) { + const element = createElement('iframe', { + src, + width: '100%', + height: '100%', + }); + + element.addEventListener('load', () => { + element.contentWindow.addEventListener('keydown', listener); + }); + + const options = { + ...Config, + }; + + if (CloudCmd.config('showFileName')) + options.title = Info.name; + + modal.open(element, options); +} + async function viewMedia(path) { const [e, element] = await getMediaElement(path); @@ -259,7 +283,12 @@ function isVideo(name) { return /\.(mp4|avi)$/i.test(name); } +const isPDF = (name) => /\.(pdf)$/i.test(name); + function getType(name) { + if (isPDF(name)) + return 'pdf'; + if (isImage(name)) return 'image';