Code source wiki de ConfigSheet

Version 3.1 par Florent Charton le 2025/07/04 23:28

Afficher les derniers auteurs
1 {{include reference="CKEditor.VelocityMacros" /}}
2
3 {{velocity}}
4 #if ($xcontext.action == 'edit')
5 {{html clean="false"}}
6 <div class="xform half">
7 #displayCKEditorConfig($doc 'edit')
8 </div>
9 {{/html}}
10 #end
11 {{/velocity}}
12
13 {{velocity wiki="false"}}
14 #if ($xcontext.action != 'edit')
15 #if ($xcontext.action == 'get')
16 #set ($discard = $response.setContentType('application/javascript'))
17 #end
18 #set ($isTemporaryAttachmentSupported = "$!services.temporaryAttachments" != '')
19 #set ($htmlSyntax = ${services.wysiwyg.HTMLSyntax.toIdString()|'annotatedxhtml/1.0'})
20 #set ($isHTML5 = !$htmlSyntax.equals('annotatedxhtml/1.0'))
21 ## Verify if the office import feature is supported.
22 ##
23 ## It's not enough to check if the Office server is connected because the 'importOfficeAttachment' API is available
24 ## only since XWiki 9.8 (see XWIKI-14739) while the CKEditor Integration extension can be installed on older versions
25 ## of XWiki where the users won't be able to import office documents from the CKEditor even if the Office server is
26 ## connected. On these older versions the users will have to use the Create Page dialog with the Page from Office
27 ## option.
28 ##
29 ## We check if the 'importOfficeAttachment' API is available by trying to import an attachment that doesn't exist
30 ## using the Office Viewer macro, which should output an error message saying that the attachment doesn't exist. This
31 ## way the Office server is not actually called so there's no risk of slowing down or blocking the CKEditor load (see
32 ## CKEDITOR-294).
33 #set ($missingAttachmentReference = $services.model.resolveAttachment('CKEditor.OfficeImporter@doesNotExist.txt'))
34 #set ($officeServerConnected = $services.officemanager.isConnected())
35 #if ("$!officeServerConnected" == '')
36 ## Before XWiki 12.3 and 11.10.5
37 #set ($officeServerConnected = $services.officemanager.serverState == 'Connected')
38 #end
39 #set ($officeImportSupported = $officeServerConnected &&
40 "$!services.wysiwyg.importOfficeAttachment($missingAttachmentReference, {'useOfficeViewer': true})" != '')
41 ## Global default configuration that doesn't depend on the edited content and that needs Velocity code for evaluation.
42 ## Static global configuration (that doesn't need Velocity) should be put in config.js . The default instance level
43 ## configuration is in EditSheet.
44 #set ($customConfig = {
45 'editorplaceholder': $services.localization.render('ckeditor.content.placeholder'),
46 'htmlSyntax': $htmlSyntax,
47 'stylesSet': "#if ($isHTML5)html5#{else}html4#end",
48 'xwiki-office': {
49 'enabled': $officeImportSupported
50 },
51 'xwiki-realtime': {
52 'stylesheets': [
53 $services.webjars.url('org.xwiki.platform:xwiki-platform-realtime-wysiwyg-webjar', 'webjar.bundle.min.css')
54 ]
55 },
56 'xwiki-upload': {
57 'isTemporaryAttachmentSupported': $isTemporaryAttachmentSupported
58 }
59 })
60 ## CKEditor uses '-' (dash) as locale separator (between the language code and the country code).
61 #set ($customConfig.language = $xcontext.locale.toString().toLowerCase().replace('_', '-'))
62 #set ($configObj = $doc.getObject('CKEditor.ConfigClass'))
63 #foreach ($propName in $configObj.propertyNames)
64 #if ($propName != 'advanced')
65 #set ($discard = $customConfig.put($propName, $configObj.getValue($propName)))
66 #end
67 #end
68 CKEDITOR.editorConfig = function(config) {
69 CKEDITOR.tools.extend(config, $jsontool.serialize($customConfig), true);
70 $!doc.getValue('advanced')
71 };
72 #end
73 {{/velocity}}