Changes for page MentionsMacro
Last modified by Sebastian Marsching on 2024/01/08 23:13
From version 8.1
edited by Sebastian Marsching
on 2023/08/13 16:20
on 2023/08/13 16:20
Change comment:
Install extension [org.xwiki.platform:xwiki-platform-mentions-ui/15.6]
To version 6.1
edited by Sebastian Marsching
on 2023/02/20 12:48
on 2023/02/20 12:48
Change comment:
Install extension [org.xwiki.platform:xwiki-platform-mentions-ui/14.10.4]
Summary
-
Objects (1 modified, 0 added, 0 removed)
Details
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -97,35 +97,19 @@ 97 97 }; 98 98 } 99 99 100 - // Enable the user mentions for the CKEditor instances that have been already created. 101 - Object.values(ckeditor.instances).forEach(maybeEnableUserMentions); 102 - // Enable the user mentions for the CKEditor instances that are going to be created from now on. 103 - ckeditor.on('instanceCreated', (event) => { 104 - maybeEnableUserMentions(event.editor); 105 - }); 106 - 107 - function maybeEnableUserMentions(editor) { 108 - return waitForEditorReady(editor).then((editor) => { 109 - // Check if the Mentions plugin is enabled for the given editor instance. 110 - // TODO: Add support for disabling the user mentions for a particular editor instance (without disabling all 111 - // types of mentions). 112 - if (editor.plugins.mentions) { 113 - editor.plugins.mentions.instances.push(new ckeditor.plugins.mentions(editor, getUserMentionsConfig(editor))); 114 - } 115 - return editor; 116 - }); 100 + function updateConfig(editor) { 101 + editor.config.mentions = editor.config.mentions || []; 102 + editor.config.mentions.push(getUserMentionsConfig(editor)); 117 117 } 118 118 119 - function waitForEditorReady(editor) { 120 - return new Promise((resolve, reject) => { 121 - if (editor.status === 'ready') { 122 - resolve(editor); 123 - } else { 124 - editor.once('instanceReady', (event) => { 125 - resolve(event.editor); 126 - }); 127 - } 105 + ckeditor.on('instanceCreated', function(event) { 106 + // The editor instance was created but it not yet initialized. Unfortunately the configuration object passed when 107 + // the instance was created has not been merged with the global configuration yet. 108 + event.editor.once('configLoaded', function(event) { 109 + // The editor configuration has been loaded (the instance configuration has been merged with the global 110 + // configuration) but the editor has not been fully initialized yet so we can modify the configuration. 111 + updateConfig(event.editor); 128 128 }); 129 - } 113 + }); 130 130 }); 131 131 });