0 Votes

Changes for page PDF Viewer Macro

Last modified by JOSE RONALDO DOS ARAUJO on 17/04/2024

From version 2.1
edited by JOSE RONALDO DOS ARAUJO
on 13/04/2024
Change comment: Install extension [com.xwiki.pdfviewer:macro-pdfviewer-ui/2.5.2]
To version 1.1
edited by JOSE RONALDO DOS ARAUJO
on 07/04/2024
Change comment: Install extension [org.xwiki.contrib:xwiki-macro-pdfviewer/1.5]

Summary

Details

Page properties
Content
... ... @@ -1,1 +1,4 @@
1 +
2 +Sample PDF Viewer
3 +
1 1  {{pdfviewer file="pdftest.pdf" /}}
pdfviewer.zip
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.ronaldo
Size
... ... @@ -1,0 +1,1 @@
1 +2.5 MB
Content
XWiki.JavaScriptExtension[0]
Caching policy
... ... @@ -1,1 +1,0 @@
1 -long
Code
... ... @@ -1,48 +1,0 @@
1 -require(['jquery'], function ($) {
2 - $(function() {
3 - const iframe = document.getElementsByClassName('pdfviewer')[0];
4 - const initPermalinkButton = function (iframe) {
5 - let viewerFrame = $(iframe);
6 - let secondaryMenuButton = viewerFrame.contents().find('#secondaryToolbarToggle');
7 - // Triggered when clicking the permalink button.
8 - let copyPdfPermalink = function () {
9 - let fileName = new URL(viewerFrame.attr('src'), location.origin).searchParams.get('file');
10 - let pdfURL = new URL(fileName, location.origin).toString();
11 - navigator.clipboard.writeText(pdfURL).then(function() {
12 - // After upgrading the parent to 13.8, the Require plugin for translations should be used.
13 - // See https://extensions.xwiki.org/xwiki/bin/view/Extension/Localization/#HFromJavaScript
14 - new XWiki.widgets.Notification(
15 - $jsontool.serialize($services.localization.render('pdfviewer.viewer.notification.linkCopied')),
16 - 'done'
17 - );
18 - }, function() {
19 - new XWiki.widgets.Notification(
20 - $jsontool.serialize($services.localization.render('pdfviewer.viewer.notification.copyLinkFail')),
21 - 'error'
22 - );
23 - });
24 - // If the secondary menu is open, we need to close it / untoggle it.
25 - if (secondaryMenuButton.hasClass('toggled')) {
26 - secondaryMenuButton.click();
27 - }
28 - };
29 - viewerFrame.contents()
30 - .find('button.permalink')
31 - .attr('title', $jsontool.serialize($services.localization.render('pdfviewer.viewer.buttons.copyLink')))
32 - .on('click', copyPdfPermalink)
33 - .find('span')
34 - .text($jsontool.serialize($services.localization.render('pdfviewer.viewer.buttons.copyLink')))
35 - .removeAttr('data-l10n-id');
36 - };
37 -
38 - if (iframe.contentDocument.readyState === 'complete') {
39 - initPermalinkButton(iframe);
40 - } else {
41 - // We setTimeout to 0 because we want all the listeners of load event to finish executing before we run our
42 - // function. This will guarantee that the permalink button will be there when initPermalinkButton runs.
43 - iframe
44 - .contentWindow
45 - .addEventListener('load', function() { setTimeout(function () { initPermalinkButton(iframe); }, 0); });
46 - }
47 - });
48 -});
Parse content
... ... @@ -1,1 +1,0 @@
1 -Yes
Use this extension
... ... @@ -1,1 +1,0 @@
1 -onDemand
XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,0 +1,25 @@
1 +{{velocity}}
2 +#set($width = $context.macro.params.width)
3 +#set($height = $context.macro.params.height)
4 +#set($file = $context.macro.params.file)
5 +#if(!$file)
6 +No pdf URL provided
7 +#else
8 +#if($file.startsWith("http"))
9 + #set($url = $file)
10 +#else
11 + #set($url = $doc.getAttachmentURL($file))
12 +#end
13 +#set($url = $escapetool.url($url))
14 +#set($pdfviewerurl = $xwiki.getDocument("XWiki.PDFViewerMacro").getAttachmentURL("pdfviewer.zip"))
15 +{{html clean=false}}
16 + <!--[if lt IE 10]>
17 + <div class="box warningmessage">PDF Viewer : Not compatible with IE < 10</div>
18 + <![endif]-->
19 + <![if !(lt IE 10)]>
20 + <iframe src="${pdfviewerurl}/pdf-viewer/web/viewer.html?file=${url}#locale=${context.language}" width="${width}" height="${height}"&></iframe>
21 + <![endif]-->
22 + </script>
23 +{{/html}}
24 +#end
25 +{{/velocity}}
Macro content availability
... ... @@ -1,0 +1,1 @@
1 +No content
Macro description
... ... @@ -1,0 +1,1 @@
1 +PDF Viewer based on Mozilla pdf.js
Macro id
... ... @@ -1,0 +1,1 @@
1 +pdfviewer
Macro name
... ... @@ -1,0 +1,1 @@
1 +pdfviewer
Supports inline mode
... ... @@ -1,0 +1,1 @@
1 +No
Macro visibility
... ... @@ -1,0 +1,1 @@
1 +Current Wiki
XWiki.WikiMacroParameterClass[0]
Parameter description
... ... @@ -1,0 +1,1 @@
1 +File or URL path to the PDF file
Parameter mandatory
... ... @@ -1,0 +1,1 @@
1 +Yes
Parameter name
... ... @@ -1,0 +1,1 @@
1 +file
XWiki.WikiMacroParameterClass[1]
Parameter default value
... ... @@ -1,0 +1,1 @@
1 +100%
Parameter name
... ... @@ -1,0 +1,1 @@
1 +width
XWiki.WikiMacroParameterClass[2]
Parameter default value
... ... @@ -1,0 +1,1 @@
1 +1000
Parameter name
... ... @@ -1,0 +1,1 @@
1 +height