From 1061537667fc37e4a0c0500920cc680fe4af92af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 26 Mar 2020 15:06:11 +0100 Subject: Enable Text to be used by Viewer outside Files app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since Nextcloud 18.0.4 the Files app triggers the "LoadViewer" event, so that event can be used to register Text with Viewer instead of doing it through the "OCA\Files::loadAdditionalScripts" event. Besides being more correct for the Files app it also makes possible to use Text when opening files through Viewer in other apps, like Talk. Note, however, that in public share pages Text is still opened using the fallback actions instead of through Viewer, as Viewer currently does not provide the share token of the public shared folder that contains the file to be opened. Signed-off-by: Daniel Calviño Sánchez --- src/viewer.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/viewer.js (limited to 'src/viewer.js') diff --git a/src/viewer.js b/src/viewer.js new file mode 100644 index 000000000..3cf67882c --- /dev/null +++ b/src/viewer.js @@ -0,0 +1,41 @@ +/* + * @copyright Copyright (c) 2019 Julius Härtl + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import ViewerComponent from './components/ViewerComponent' +import { openMimetypesMarkdown, openMimetypesPlainText } from './helpers/mime' + +__webpack_nonce__ = btoa(OC.requestToken) // eslint-disable-line +__webpack_public_path__ = OC.linkTo('text', 'js/') // eslint-disable-line + +document.addEventListener('DOMContentLoaded', () => { + if (typeof OCA.Viewer === 'undefined') { + console.error('Viewer app is not installed') + return + } + + OCA.Viewer.registerHandler({ + id: 'text', + mimes: [...openMimetypesMarkdown, ...openMimetypesPlainText], + component: ViewerComponent, + group: null, + }) +}) -- cgit v1.2.3