Änderungen von Dokument View File Macro

Zuletzt geändert von Daniel Herrmann am 2026/02/04 20:25

Von Version Icon 4.1 Icon
bearbeitet von Daniel Herrmann
am 2025/06/23 21:15
Änderungskommentar: Install extension [com.xwiki.pro:xwiki-pro-macros-ui/1.27.0]
Auf Version Icon 3.1 Icon
bearbeitet von Daniel Herrmann
am 2025/06/23 19:53
Änderungskommentar: Install extension [com.xwiki.pro:xwiki-pro-macros-ui/1.26.19]

Zusammenfassung

Details

Icon XWiki.JavaScriptExtension[0]
Code
... ... @@ -9,175 +9,90 @@
9 9  // are shown, a custom implementation was made to dynamically update the displyed attachments in corelation to the
10 10  // selected page parameter. This can be removed after the implementation of https://jira.xwiki.org/browse/XWIKI-22850.
11 11  require(['jquery', 'xwiki-meta', 'xwiki-suggestAttachments'], function($, xm) {
12 - require(['collabora-utils'], function(collabora) {
13 - initUI(collabora);
14 - }, function (err) {
15 - console.warn('collabora-utils not found, continuing without it.');
16 - initUI(null);
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 + }
17 17   });
18 18  
19 - function initUI(collabora) {
20 - const acceptedExtensions = '.ppt,.pptx,.odp,.doc,.docx,.odt,.xls,.xlsx,.ods,.pdf';
21 - const styleObserver = new MutationObserver(function(mutations) {
22 - for (const mutation of mutations) {
23 - if (mutation.target.style.display === 'none') {
24 - styleObserver.disconnect();
25 - pageObserver.observe(document.body, { childList: true, subtree: true });
26 - return;
27 - }
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;
28 28   }
29 - });
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 + }
30 30  
31 - const initializeAttachments = function(selectElement) {
32 - let scope = "document:";
33 - if (selectElement.val() != null) {
34 - scope += selectElement.val();
35 - }
36 - var inputElement = $('input[name="name"]');
37 - if (inputElement.length) {
38 - let selectize = inputElement.siblings('.selectize-control');
39 - if (selectize.length) {
40 - selectize.remove();
41 - inputElement.removeAttr("class tabindex style").val('');
42 - const clone = inputElement.clone().appendTo(inputElement.parent());
43 - inputElement.remove();
44 - inputElement = clone;
45 - }
46 - const allowUpload = selectElement.val() == xm.document || !selectElement.val();
47 - inputElement.suggestAttachments({
48 - maxItems: 1,
49 - accept: acceptedExtensions,
50 - searchScope: scope,
51 - uploadAllowed: allowUpload
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))
52 52   });
58 + initializeAttachments(selectElement)
53 53   }
54 - };
60 + }
61 + });
55 55  
56 - const pageObserver = new MutationObserver(function(mutationsList, observer) {
57 - const selectElement = $('select[name="page"]');
58 - if (selectElement.length) {
59 - const modal = selectElement.closest(".macro-editor-modal")[0];
60 - if (modal.style.display !== 'none') {
61 - observer.disconnect();
62 - styleObserver.observe(modal, { attributes: true, attributeFilter: ['style'] });
63 - $(selectElement).change(function() {
64 - initializeAttachments($(this))
65 - });
66 - initializeAttachments(selectElement)
67 - }
68 - }
69 - });
63 + pageObserver.observe(document.body, { childList: true, subtree: true });
64 +});
70 70  
71 - pageObserver.observe(document.body, { childList: true, subtree: true });
72 -
73 - const getFileExtension = function(fileName) {
74 - return fileName.slice(fileName.lastIndexOf('.') + 1).toLowerCase();
75 - };
76 -
77 - const decorateWithCollaboraButton = function(viewFile, fileRef, spanContainer) {
78 - const attachment = XWiki.Model.resolve(fileRef, XWiki.EntityType.ATTACHMENT);
79 - var fileName = attachment.getName();
80 - var collaboraButton = $(viewFile).find('a.collaboraEdit');
81 - if (collaboraButton.length != 0) {
82 - const accessRights = collabora.getAccessRights(fileName);
83 - if (!accessRights) {
84 - return;
85 - }
86 - collabora.populateCollaboraButton(collaboraButton, fileName, accessRights, XWiki.Model.serialize(attachment.parent));
87 - const clonedButton = collaboraButton.clone(true, true);
88 - clonedButton.addClass('btn btn-default');
89 - clonedButton.addClass('viewfile-header-button');
90 - clonedButton.attr('target', '_blank');
91 - $(spanContainer).find('.viewFileModal-downloadLink').after(clonedButton);
66 +window.addEventListener("DOMContentLoaded", function () {
67 + "use strict";
68 + document.addEventListener("click", async function (e) {
69 + if (("" + document.getElementById("xwikicontent")?.contentEditable) == "true") {
70 + return;
71 + }
72 + const viewFile = e.target?.closest(".viewFileThumbnail");
73 + if (viewFile && viewFile.dataset.preview === 'true') {
74 + const popup = new XWiki.widgets.ModalPopup();
75 + popup.createDialog();
76 + popup.setContent("<span class='fa fa-spinner'></span>");
77 + popup.dialogBox.classList.add("viewFileModal");
78 + popup.dialogBox.style.top = "2.5vh";
79 + popup.dialogBox.style.width = "95vw";
80 + popup.dialogBox.style.height = "95vh";
81 + const a = e.target.closest('a');
82 + const downloadLink = document.createElement("a");
83 + downloadLink.download = true;
84 + downloadLink.textContent = a.textContent;
85 + downloadLink.className = "fa fa-download button button-primary viewFileModal-downloadLink";
86 + downloadLink.href = a.href;
87 + popup.dialogBox.insertBefore(downloadLink, popup.dialogBox.firstChild)
88 + popup.showDialog();
89 + e.preventDefault();
90 + const response = await fetch(XWiki.contextPath + "/wiki/" + XWiki.currentWiki + "/get/Confluence/Macros/ViewFileService?action=render&attachment=" + encodeURIComponent(viewFile.dataset.ref));
91 + popup.setContent(await response.text());
92 + const gallery = popup.dialogBox.querySelector(".gallery");
93 + if (gallery) {
94 + new XWiki.Gallery(gallery);
92 92   }
93 - };
94 -
95 - // This function has been taken from OnlyOffice Connector Application, as it's being used to determine what
96 - // action the user can take on a file depending on the file extension.
97 - const determineOOAction = function(fileRef) {
98 - var ooCanDoByExt = { };
99 - const editableFormats = ['docx', 'xlsx', 'pptx'];
100 - const convertibleFormats = ['odt', 'ods', 'odp', 'xls', 'csv', 'doc', 'ppt', 'pps', 'ppsx', 'rtf', 'txt', 'mht',
101 - 'html', 'htm'];
102 - editableFormats.forEach(function(x) {
103 - ooCanDoByExt[x] = 'edit';
104 - });
105 - convertibleFormats.forEach(function(x) {
106 - ooCanDoByExt[x] = 'convert';
107 - });
108 - ['pdf', 'djvu', 'fb2', 'epub', 'xps'].forEach(function(x) {
109 - ooCanDoByExt[x] = 'view';
110 - });
111 - var fileType = getFileExtension(fileRef);
112 - return ooCanDoByExt[fileType];
113 - };
114 -
115 - const decorateWithXooButton = function(viewFile, fileRef, spanContainer) {
116 - if ($(viewFile).find('span.oo-installed-check').data('ooexists')) {
117 - var whatCanDo = determineOOAction(fileRef);
118 - if (!whatCanDo) {
119 - return;
120 - }
121 - if (!XWiki.hasEdit) {
122 - whatCanDo = 'view';
123 - }
124 - const attachment = XWiki.Model.resolve(fileRef, XWiki.EntityType.ATTACHMENT);
125 - var queryString = $.param({
126 - 'elem': 'oOActionButtons',
127 - 'document': XWiki.Model.serialize(attachment.parent),
128 - 'filename': attachment.getName(),
129 - 'whatCanDo': whatCanDo,
130 - 'asLink': true
131 - });
132 -
133 - $.post(new XWiki.Document('UI', 'XWikiOnlyOfficeCode').getURL('get', queryString), function(data) {
134 - const $button = $(data);
135 - $button.addClass('btn btn-default');
136 - $button.addClass('viewfile-header-button');
137 - $button.attr('target', '_blank');
138 - $(spanContainer).find('.viewFileModal-downloadLink').after($button);
139 - });
140 - }
141 - };
142 -
143 - $(document).on("click", async function (e) {
144 - if (("" + document.getElementById("xwikicontent")?.contentEditable) == "true") {
145 - return;
146 - }
147 - const viewFile = e.target?.closest(".viewFileThumbnail");
148 - if (viewFile && viewFile.dataset.preview === 'true') {
149 - const fileRef = viewFile.dataset.ref;
150 - const popup = new XWiki.widgets.ModalPopup();
151 - popup.createDialog();
152 - popup.setContent("<span class='fa fa-spinner'></span>");
153 - popup.dialogBox.classList.add("viewFileModal");
154 - popup.dialogBox.style.top = "2.5vh";
155 - popup.dialogBox.style.width = "95vw";
156 - popup.dialogBox.style.height = "95vh";
157 - const a = e.target.closest('a');
158 - const downloadLink = document.createElement('a');
159 - const spanContainer = document.createElement('span');
160 - spanContainer.className = 'viewfile-actions-header';
161 - downloadLink.download = true;
162 - downloadLink.textContent = ' ' + $(a).find('.viewFileName').text();
163 - downloadLink.className = 'fa fa-download button button-primary viewFileModal-downloadLink viewfile-header-button';
164 - downloadLink.href = a.href;
165 - spanContainer.appendChild(downloadLink);
166 - decorateWithXooButton(viewFile, fileRef, spanContainer);
167 - if (collabora != null) {
168 - decorateWithCollaboraButton(viewFile, fileRef, spanContainer);
169 - }
170 - $(popup.dialogBox).prepend(spanContainer);
171 - popup.showDialog();
172 - e.preventDefault();
173 - const response = await fetch(XWiki.contextPath + '/wiki/' + XWiki.currentWiki +
174 - '/get/Confluence/Macros/ViewFileService?action=render&attachment=' + encodeURIComponent(fileRef));
175 - popup.setContent(await response.text());
176 - const gallery = popup.dialogBox.querySelector(".gallery");
177 - if (gallery) {
178 - new XWiki.Gallery(gallery);
179 - }
180 - }
181 - });
182 - }
96 + }
97 + });
183 183  });
Icon XWiki.StyleSheetExtension[0]
Code
... ... @@ -1,5 +3,3 @@
1 -#template('colorThemeInit.vm')
2 -
3 3  .viewFileModal iframe, .viewFileModal .xdialog-content {
4 4   height: calc(95vh - 5em);
5 5  }
... ... @@ -86,41 +86,3 @@
86 86  .viewFileName {
87 87   overflow-wrap: break-word;
88 88  }
89 -
90 -.image-container {
91 - position: relative;
92 -}
93 -
94 -.viewfile-thumbnail-image {
95 - display: block;
96 -}
97 -
98 -.overlay {
99 - position: absolute;
100 - inset: 0px;
101 - opacity: 0;
102 - transition: .7s ease;
103 - background-color: $theme.buttonPrimaryBackgroundColor;
104 -}
105 -
106 -.image-container:hover .overlay {
107 - opacity: 1;
108 -}
109 -
110 -.overlay-text {
111 - color: $theme.buttonPrimaryTextColor;
112 - font-size: 2rem;
113 - position: absolute;
114 - top: 50%;
115 - left: 50%;
116 - transform: translate(-50%, -50%);
117 - text-align: center;
118 -}
119 -
120 -.viewfile-header-button {
121 - margin: 1rem 0.7rem;
122 -}
123 -
124 -.viewfile-actions-header {
125 - margin: 1rem;
126 -}
Inhalt parsen
... ... @@ -1,1 +1,1 @@
1 -Ja
1 +Nein