Changes for page MentionsMacro

on 2023-11-02 09:50


on 2022-03-20 10:03
Summary
Details
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -1,6 +1,6 @@ 1 1 require.config({ 2 2 paths: { 3 - 'xwiki-suggestUsers': $jsontool.serialize($xwiki.getSkinFile('uicomponents/suggest/suggestUsersAndGroups.js')) 3 + 'xwiki-suggestUsers': $jsontool.serialize($xwiki.getSkinFile('uicomponents/suggest/suggestUsersAndGroups.js', true)) 4 4 } 5 5 }); 6 6 require(['deferred!ckeditor', 'xwiki-suggestUsers', 'jquery', 'xwiki-meta'], function (ckeditorPromise, suggestUsers, $, xm) { ... ... @@ -60,7 +60,7 @@ 60 60 } 61 61 62 62 ckeditorPromise.then(ckeditor => { 63 - function getUserMentionsConfig(editor) {63 + function confMentions(name) { 64 64 return { 65 65 feed: function (opts, callback) { 66 66 search(opts.query, callback); ... ... @@ -68,18 +68,18 @@ 68 68 marker: '@', 69 69 minChars: 0, 70 70 itemsLimit: 6, 71 - itemTemplate: 72 - `<li data-id="{id}" class="ckeditor-autocomplete-item"> 73 - <div> 74 - <span class="ckeditor-autocomplete-item-icon-wrapper"> 75 - <span class="{cssClass}"></span> 76 - <img src="{imgUrl}" class="{imgClass}"/> 77 - </span> 78 - <span class="ckeditor-autocomplete-item-label">{label}</span> 79 - </div> 80 - </li>`, 71 + itemTemplate: '<li data-id="{id}" class="ckeditor-autocomplete-item">'+ 72 + '<div>'+ 73 + '<span class="ckeditor-autocomplete-item-icon-wrapper">'+ 74 + '<span class="{cssClass}"></span>'+ 75 + '<img src="{imgUrl}" class="{imgClass}"/>'+ 76 + '</span>'+ 77 + '<span class="ckeditor-autocomplete-item-label">{label}</span>'+ 78 + '</div>'+ 79 + '</li>', 81 81 outputTemplate: function (param) { 82 - editor.once('afterInsertHtml', function() { 81 + var editor = ckeditor.instances[name]; 82 + editor.once('afterInsertHtml', function () { 83 83 editor.execCommand('xwiki-macro-insert', { 84 84 name: 'mention', 85 85 inline: 'enforce', ... ... @@ -97,35 +97,21 @@ 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 updateConf(config, name) { 101 + const newConf = config || {}; 102 + newConf.mentions = newConf.mentions || []; 103 + newConf.mentions.push(confMentions(name)); 104 + return newConf; 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 - } 128 - }); 129 - } 107 + var oldReplace = ckeditor.replace; 108 + ckeditor.replace = function (element, config) { 109 + return oldReplace.call(this, element, updateConf(config, element.id)); 110 + }; 111 + 112 + var oldInline = ckeditor.inline; 113 + ckeditor.inline = function (element, config) { 114 + return oldInline.call(this, element, updateConf(config, element.id)); 115 + }; 130 130 }); 131 131 });
- XWiki.StyleSheetExtension[0]
-
- Code
-
... ... @@ -1,6 +1,6 @@ 1 1 .xwiki-mention { 2 2 background-color: $services.mentions.mentionsColor; 3 - border-radius: 10px;3 + border-radius: 8px; 4 4 padding: 2px 5px 2px 5px; 5 5 } 6 6
- XWiki.WikiMacroClass[0]
-
- Macro code
-
... ... @@ -11,8 +11,6 @@ 11 11 #end 12 12 #set ($link = $xwiki.getURL($reference.reference, 'view')) 13 13 {{html}} 14 -<a id="$escapetool.xml($anchor)" class="$stringtool.join($cssClasses, ' ')" data-reference="$escapetool.xml($services.model.serialize($reference.reference, 'default'))" href="$escapetool.xml($link)">## 15 - $escapetool.xml($content)## Do not remove this comment as it ensures that the spacing after mention is not broken. 16 -</a> 14 +<a id="$anchor" class="$stringtool.join($cssClasses, ' ')" data-reference="$services.model.serialize($reference.reference, 'default')" href="$link">$content</a> 17 17 {{/html}} 18 18 {{/velocity}} - Default category
-
... ... @@ -1,0 +1,1 @@ 1 +Notifications - Default categories
-
... ... @@ -1,1 +1,0 @@ 1 -Notifications