Changes for page View File Macro
Last modified by Frank Fock on 2025/04/04 21:18
From version 4.1
edited by Frank Fock
on 2025/04/04 21:18
on 2025/04/04 21:18
Change comment:
Install extension [com.xwiki.pro:xwiki-pro-macros-ui/1.26.14]
To version 3.1
edited by Frank Fock
on 2025/01/26 23:11
on 2025/01/26 23:11
Change comment:
Install extension [com.xwiki.pro:xwiki-pro-macros-ui/1.25.5]
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Objects (2 modified, 6 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -6,11 +6,10 @@ 6 6 7 7 |=Parameter|=Description|=Required|=Default 8 8 |display|Kind of display. "button" for a button, "thumbnail" for a thumbnail, "full" to render the document in place|no|thumbnail (button in inline mode) 9 -|name|The attachment reference to display|if att--filename is not given| 10 -|page|The page from where you want the attachments to be displayed. Modifying this parameter will reset the selected file value|no| 9 +|name|The attachment reference to display|if att-filename is not given| 11 11 |width|The width of the view in % or px (e.g. 100%, 100px)|no|100% for the full view or 100px for the thumbnail 12 12 |height|The height of the view in % or px (e.g. 100%, 100px)|no|1000px for the full view or 100px for the thumbnail 13 -|att- -filename|Alias of name|If name is not given|12 +|att-filename|Alias of name|If name is not given| 14 14 15 15 = Example Usage = 16 16
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -1,68 +66,3 @@ 1 -require.config({ 2 - paths: { 3 - 'xwiki-suggestAttachments': "$xwiki.getSkinFile('uicomponents/suggest/suggestAttachments.js', true)" + 4 - "?v=$escapetool.url($xwiki.version)" 5 - } 6 -}); 7 - 8 -// As there is no platform implementation to allow the user to dynamically select the page from where the attachments 9 -// are shown, a custom implementation was made to dynamically update the displyed attachments in corelation to the 10 -// selected page parameter. This can be removed after the implementation of https://jira.xwiki.org/browse/XWIKI-22850. 11 -require(['jquery', 'xwiki-meta', 'xwiki-suggestAttachments'], function($, xm) { 12 - const acceptedExtensions = '.ppt,.pptx,.odp,.doc,.docx,.odt,.xls,.xlsx,.ods,.pdf'; 13 - const styleObserver = new MutationObserver(function(mutations) { 14 - for (const mutation of mutations) { 15 - if (mutation.target.style.display === 'none') { 16 - styleObserver.disconnect(); 17 - pageObserver.observe(document.body, { childList: true, subtree: true }); 18 - return; 19 - } 20 - } 21 - }); 22 - 23 - const initializeAttachments = function(selectElement) { 24 - let scope = "document:"; 25 - if (selectElement.val() != null) { 26 - scope += selectElement.val(); 27 - } 28 - var inputElement = $('input[name="name"]'); 29 - if (inputElement.length) { 30 - let selectize = inputElement.siblings('.selectize-control'); 31 - if (selectize.length) { 32 - selectize.remove(); 33 - inputElement.removeAttr("class tabindex style").val(''); 34 - const clone = inputElement.clone().appendTo(inputElement.parent()); 35 - inputElement.remove(); 36 - inputElement = clone; 37 - } 38 - const allowUpload = selectElement.val() == xm.document || !selectElement.val(); 39 - inputElement.suggestAttachments({ 40 - maxItems: 1, 41 - accept: acceptedExtensions, 42 - searchScope: scope, 43 - uploadAllowed: allowUpload 44 - }); 45 - } 46 - } 47 - 48 - const pageObserver = new MutationObserver(function(mutationsList, observer) { 49 - const selectElement = $('select[name="page"]'); 50 - if (selectElement.length) { 51 - const modal = selectElement.closest(".macro-editor-modal")[0]; 52 - if (modal.style.display !== 'none') { 53 - observer.disconnect(); 54 - styleObserver.observe(modal, { attributes: true, attributeFilter: ['style'] }); 55 - $(selectElement).change(function() { 56 - initializeAttachments($(this)) 57 - }); 58 - initializeAttachments(selectElement) 59 - } 60 - } 61 - }); 62 - 63 - pageObserver.observe(document.body, { childList: true, subtree: true }); 64 -}); 65 - 66 66 window.addEventListener("DOMContentLoaded", function () { 67 67 "use strict"; 68 68 document.addEventListener("click", async function (e) { - Parse content
-
... ... @@ -1,1 +1,1 @@ 1 - Yes1 +No
- XWiki.StyleSheetExtension[0]
-
- Code
-
... ... @@ -42,10 +42,6 @@ 42 42 43 43 .viewFileThumbnailCard, .viewFileFull { 44 44 position: relative; 45 - width: 10rem !important; 46 - height: fit-content; 47 - min-height: 10rem !important; 48 - margin-bottom: 1rem !important; 49 49 } 50 50 51 51 span.viewFileThumbnailCard { ... ... @@ -58,7 +58,7 @@ 58 58 flex-direction: column; 59 59 text-align: center; 60 60 width: 100%; 61 - min-height:inherit;57 + height: 100%; 62 62 } 63 63 64 64 .viewFileThumbnailCard a .attachmentMimeType { ... ... @@ -71,13 +71,8 @@ 71 71 width: 100%; 72 72 border: 1px solid; 73 73 border-radius: 1rem; 74 - min-height: 5em; 75 75 } 76 76 77 77 .viewFileModal-downloadLink { 78 78 margin-left: 2px; 79 79 } 80 - 81 -.viewFileName { 82 - overflow-wrap: break-word; 83 -}
- XWiki.WikiMacroClass[0]
-
- Cached
-
... ... @@ -1,0 +1,1 @@ 1 +No - Asynchronous rendering
-
... ... @@ -1,0 +1,1 @@ 1 +No - Macro code
-
... ... @@ -1,0 +1,157 @@ 1 +{{velocity output="false"}} 2 +#template('attachment_macros.vm') 3 + 4 +#set ($officeExtensions = [ 'ppt', 'pptx', 'odp', 'doc', 'docx', 'odt', 'xls', 'xlsx', 'ods' ]) 5 +#set ($presentationExtensions = [ 'ppt', 'pptx', 'odp' ]) 6 +#set ($hasPDFViewer = $xwiki.exists("XWiki.PDFViewerMacro")) 7 + 8 +#macro (renderThumbnailButton $attachmentRef $previewSupported $width $height $forceCard) 9 + #set ($style = "") 10 + #if ("$!width" != "") 11 + #set ($style = $style + " width: $width") 12 + #end 13 + #if ("$!height" != "") 14 + #set ($style = $style + " height: $height") 15 + #end 16 + #if ("$!style" != "") 17 + #set ($style = "style='$style.trim()'") 18 + #set ($thumbnailStyle = "Card") 19 + #elseif ($forceCard) 20 + #set ($style = "style='width: 100px; height: 100px;'") 21 + #set ($height = "100px") 22 + #set ($thumbnailStyle = "Card") 23 + #else 24 + #set ($thumbnailStyle = "Button") 25 + #end 26 + #if ($wikimacro.context.isInline() || $thumbnailStyle == "Button") 27 + #set ($elem = "span") 28 + #set ($clean = false) 29 + #else 30 + #set ($elem = "div") 31 + #set ($clean = true) 32 + #end 33 + #set ($attachment = $xwiki.getDocument($attachmentRef.getParent()).getAttachment($attachmentRef.getName())) 34 + #set ($thumbnail = "#displayAttachmentMimeType($attachment)") 35 + #if ($thumbnail.charAt(0) == '#') 36 + ## #displayAttachmentMimeType is not supported (before July 2022) 37 + #set ($thumbnail = '<div class="attachmentMimeType"><span><span class="fa fa-paperclip" aria-hidden="true"></span></span></div>') 38 + #end 39 + #if ($elem == "span") 40 + #set ($thumbnail = $thumbnail.replace('</div>', '</span>').replace('<div ', '<span ')) 41 + #end 42 + 43 + {{html clean="$clean"}} 44 + <$elem class="viewFileThumbnail viewFileThumbnail$thumbnailStyle" $style data-preview="$previewSupported" data-ref="$escapetool.xml($services.model.serialize($attachmentRef, 'default'))"> 45 + <a href="$escapetool.xml($xwiki.getURL($attachmentRef))" 46 + download="download" 47 + #if ($thumbnailStyle == "Button") class="button button-primary" #end 48 + title="$escapetool.xml($services.localization.render('rendering.macro.viewFile.thumbnail.button.title'))" 49 + > 50 + $thumbnail 51 + <span class="viewFileName">$escapetool.xml($attachmentRef.getName())</span> 52 + </a> 53 + </$elem> 54 + {{/html}} 55 + 56 +#end 57 + 58 +#macro (renderFull $extension $attachmentRef $width $height) 59 + #set ($escapedAttachmentReference = $services.rendering.escape($attachmentRef, $xwiki.currentContentSyntaxId)) 60 + #if ($officeExtensions.contains($extension)) 61 + 62 + {{html clean=false}} 63 + <div class="viewFileFull#if (!$presentationExtensions.contains($extension)) box#end" 64 + style="width: $width; height: $height; overflow: auto"> 65 + {{/html}} 66 + 67 + {{office reference="$escapedAttachmentReference" /}} 68 + 69 + {{html clean=false}} 70 + </div> 71 + {{/html}} 72 + 73 + #elseif ($extension == 'pdf' && $hasPDFViewer) 74 + #if ($height.endsWith("px")) 75 + #set ($height = $stringtool.removeEnd($height, "px")) 76 + #end 77 + #if ($width.endsWith("px")) 78 + #set ($width = $stringtool.removeEnd($width, "px")) 79 + #end 80 + 81 + {{pdfviewer file="$escapedAttachmentReference" height="$height" width="$width"/}} 82 + 83 + #else 84 + #renderThumbnailButton($attachmentRef false $width $height) 85 + #end 86 +#end 87 + 88 +#macro (executeMacro) 89 + #set($unescapedFilename = $xcontext.macro.params.get('att--filename')) 90 + #if(!$unescapedFilename) 91 + #set($unescapedFilename = $xcontext.macro.params.get('name')) 92 + #end 93 + #if(!$unescapedFilename) 94 + 95 + {{error}} 96 + $escapetool.xml($services.localization.render('rendering.macro.viewFile.namerequired'))" 97 + {{/error}} 98 + #end 99 + #continueExecutingMacro## 100 +#end 101 + 102 +#macro (continueExecutingMacro) 103 + #set ($attachmentRef = $services.model.resolveAttachment($unescapedFilename)) 104 + #set ($discard = $xwiki.ssx.use('Confluence.Macros.ViewFile')) 105 + #set ($extension = $unescapedFilename.substring($unescapedFilename.lastIndexOf('.') + 1).toLowerCase()) 106 + #set ($width = $xcontext.macro.params.get('width')) 107 + #set ($height = $xcontext.macro.params.get('height')) 108 + #set ($display = $xcontext.macro.params.get('display')) 109 + #if ("$!width" != "") 110 + #set ($width = $escapetool.xml($width)) 111 + #if (!$width.endsWith("%") && !$width.endsWith("px")) 112 + #set($width = $width + "px") 113 + #end 114 + #end 115 + #if ("$!height" != "") 116 + #set ($height = $escapetool.xml($height)) 117 + #if (!$height.endsWith("%") && !$height.endsWith("px")) 118 + #set($height = $height + "px") 119 + #end 120 + #end 121 + #if (($display == 'FULL' || $display == 'full') && ($wikimacro.context.isInline() || ($xcontext.action == "edit" || $request.outputSyntax == "annotatedhtml"))) 122 + #set ($display = "thumbnail") 123 + #end 124 + #if ($display == 'FULL' || $display == 'full') 125 + #if ("$!width" == "") 126 + #set ($width = "100%") 127 + #end 128 + #if ("$!height" == "") 129 + #set ($height = "1000px") 130 + #end 131 + #renderFull($extension $attachmentRef $width $height) 132 + #else 133 + ## thumbnail or fallback 134 + #set ($hasPreview = ($extension == 'pdf' && $hasPDFViewer) || $officeExtensions.contains($extension)) 135 + #if ($hasPreview) 136 + #set ($discard = $xwiki.jsx.use('Confluence.Macros.ViewFile')) 137 + #end 138 + #set ($forceCard = ($display == 'THUMBNAIL' || $display == 'thumbnail' || ("$!display" == "" && !$wikimacro.context.isInline()))) 139 + #if ($presentationExtensions.contains($extension)) 140 + #set ($discard = $xwiki.jsfx.use("uicomponents/widgets/gallery/gallery.js", {"forceSkinAction": true})) 141 + #set ($discard = $xwiki.ssfx.use("uicomponents/widgets/gallery/gallery.css")) 142 + #end 143 + #renderThumbnailButton($attachmentRef $hasPreview $width $height $forceCard) 144 + #end 145 +#end 146 +{{/velocity}} 147 + 148 +{{velocity}} 149 +## We need to check if there is a valid license because the macro is registered even if the user doesn't have view right 150 +## on the macro definition page. See XWIKI-14828: Rendering macros defined in wiki pages are available to users that 151 +## don't have view right on those pages. 152 +#if ($services.promacrolicensing.hasLicensureForEntity($xcontext.macro.doc.documentReference))## 153 + #executeMacro## 154 +#else 155 + {{missingLicenseMessage extensionName="proMacros.extension.name"/}} 156 +#end 157 +{{/velocity}} - Macro content availability
-
... ... @@ -1,0 +1,1 @@ 1 +No content - Macro description
-
... ... @@ -1,0 +1,1 @@ 1 +Show files using PDF Viewer Macro or Office Viewer - Macro id
-
... ... @@ -1,0 +1,1 @@ 1 +view-file - Macro name
-
... ... @@ -1,0 +1,1 @@ 1 +View Files - Supports inline mode
-
... ... @@ -1,0 +1,1 @@ 1 +Yes - Macro visibility
-
... ... @@ -1,0 +1,1 @@ 1 +Current Wiki
- XWiki.WikiMacroParameterClass[0]
-
- Parameter description
-
... ... @@ -1,0 +1,1 @@ 1 +Alias of name (here for compatibility reasons) - Parameter mandatory
-
... ... @@ -1,0 +1,1 @@ 1 +No - Parameter name
-
... ... @@ -1,0 +1,1 @@ 1 +att--filename - Parameter type
-
... ... @@ -1,0 +1,1 @@ 1 +org.xwiki.model.reference.AttachmentReference
- XWiki.WikiMacroParameterClass[1]
-
- Parameter description
-
... ... @@ -1,0 +1,1 @@ 1 +The width of the view in % or px (e.g. 100%, 100px) - Parameter mandatory
-
... ... @@ -1,0 +1,1 @@ 1 +No - Parameter name
-
... ... @@ -1,0 +1,1 @@ 1 +width
- XWiki.WikiMacroParameterClass[2]
-
- Parameter description
-
... ... @@ -1,0 +1,1 @@ 1 +The height of the view in % or px (e.g. 100%, 100px) - Parameter mandatory
-
... ... @@ -1,0 +1,1 @@ 1 +No - Parameter name
-
... ... @@ -1,0 +1,1 @@ 1 +height
- XWiki.WikiMacroParameterClass[3]
-
- Parameter description
-
... ... @@ -1,0 +1,1 @@ 1 +Kind of display. "button" for a button, "thumbnail" for a thumbnail, "full" to render the document in place - Parameter mandatory
-
... ... @@ -1,0 +1,1 @@ 1 +No - Parameter name
-
... ... @@ -1,0 +1,1 @@ 1 +display - Parameter type
-
... ... @@ -1,0 +1,1 @@ 1 +com.xwiki.macros.internal.ViewFileDisplay
- XWiki.WikiMacroParameterClass[4]
-
- Parameter description
-
... ... @@ -1,0 +1,1 @@ 1 +The attachment reference to display - Parameter mandatory
-
... ... @@ -1,0 +1,1 @@ 1 +No - Parameter name
-
... ... @@ -1,0 +1,1 @@ 1 +name - Parameter type
-
... ... @@ -1,0 +1,1 @@ 1 +org.xwiki.model.reference.AttachmentReference