Wijzigen voor document MentionsMacro
Laatst gewijzigd door admin op 10-04-2026
Samenvatting
-
Objecten (3 gewijzigd, 0 toegevoegd, 0 verwijderd)
Details
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -1,15 +1,15 @@ 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) { 7 - 7 + 8 8 /** 9 9 * Get the current wiki scope for displaying global, local or global and local users 10 10 */ 11 11 const userScope = "$!services.wiki.user.userScope"; 12 - 12 + 13 13 // see https://stackoverflow.com/a/6248722/657524 14 14 function random6chars() { 15 15 // I generate the UID from two parts here ... ... @@ -20,7 +20,7 @@ 20 20 secondPart = ("000" + secondPart.toString(36)).slice(-3); 21 21 return firstPart + secondPart; 22 22 } 23 - 23 + 24 24 /** 25 25 * Compute a new unique anchor for the given reference. 26 26 * The unique anchor is based on the mentionned user id, concatenaed with a random string of 6 alphanumeric ... ... @@ -39,8 +39,8 @@ 39 39 'input': text, 40 40 'limit': 6, 41 41 }; 42 - suggestUsers.loadUsers(userScope, params).then(user s=>{43 - const cct = user s.map(function (x) {42 + $.when(suggestUsers.loadUsers(userScope, params)).then(function (user) { 43 + const cct = user.map(function (x) { 44 44 // insert an id because that's required by the mentions plugins. 45 45 x.id = x.value; 46 46 // Make sure to display the icon avatar or the image one. ... ... @@ -56,32 +56,30 @@ 56 56 return x; 57 57 }); 58 58 callback(cct); 59 - }) ;59 + }) 60 60 } 61 61 62 - ckeditorPromise. then(ckeditor=>{63 - function getUserMentionsConfig(editor) {62 + ckeditorPromise.done(function (ckeditor) { 63 + function confMentions(name) { 64 64 return { 65 - dataCallback: function (options, callback) { 66 - // Remove the marker prefix and replace non-breaking space. 67 - const text = options.query.substring(1).replaceAll('\u00A0', ' '); 68 - search(text, callback); 65 + feed: function (opts, callback) { 66 + search(opts.query, callback); 69 69 }, 70 70 marker: '@', 71 71 minChars: 0, 72 72 itemsLimit: 6, 73 - itemTemplate: 74 - `<li data-id="{id}" class="ckeditor-autocomplete-item"> 75 - <div> 76 - <span class="ckeditor-autocomplete-item-icon-wrapper"> 77 - <span class="{cssClass}"></span> 78 - <img src="{imgUrl}" class="{imgClass}"/> 79 - </span> 80 - <span class="ckeditor-autocomplete-item-label">{label}</span> 81 - </div> 82 - </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>', 83 83 outputTemplate: function (param) { 84 - editor.once('afterInsertHtml', function() { 81 + var editor = ckeditor.instances[name]; 82 + editor.once('afterInsertHtml', function () { 85 85 editor.execCommand('xwiki-macro-insert', { 86 86 name: 'mention', 87 87 inline: 'enforce', ... ... @@ -99,30 +99,21 @@ 99 99 }; 100 100 } 101 101 102 - // Enable the user mentions for the CKEditor instances that have been already created. 103 - Object.values(ckeditor.instances).forEach(maybeEnableUserMentions); 104 - // Enable the user mentions for the CKEditor instances that are going to be created from now on. 105 - ckeditor.on('instanceCreated', (event) => { 106 - maybeEnableUserMentions(event.editor); 107 - }); 108 - 109 - function maybeEnableUserMentions(editor) { 110 - return waitForEditorReady(editor).then(editor => { 111 - new CKEDITOR.plugins.AdvancedAutoComplete(editor, getUserMentionsConfig(editor)); 112 - return editor; 113 - }); 100 + function updateConf(config, name) { 101 + const newConf = config || {}; 102 + newConf.mentions = newConf.mentions || []; 103 + newConf.mentions.push(confMentions(name)); 104 + return newConf; 114 114 } 115 115 116 - function waitForEditorReady(editor) { 117 - return new Promise((resolve, reject) => { 118 - if (editor.status === 'ready') { 119 - resolve(editor); 120 - } else { 121 - editor.once('instanceReady', (event) => { 122 - resolve(event.editor); 123 - }); 124 - } 125 - }); 126 - } 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 + }; 127 127 }); 128 128 });
- XWiki.StyleSheetExtension[0]
-
- Code
-
... ... @@ -1,17 +1,11 @@ 1 1 .xwiki-mention { 2 - --mentions-color: $services.mentions.mentionsColor; 3 - --mentions-self-color: $services.mentions.selfMentionsForeground; 4 - --mentions-self-bg: $services.mentions.selfMentionsColor; 5 - background-color: var(--mentions-color); 6 - border-radius: 10px; 7 - padding: 1px 5px 1px 5px; 8 - border: 1px solid var(--dropdown-divider-bg); 2 + background-color: $services.mentions.mentionsColor; 3 + border-radius: 8px; 4 + padding: 2px 5px 2px 5px; 9 9 } 10 10 11 11 .xwiki-mention.user.self { 12 - background-color: var(--mentions-self-bg); 13 - color: var(--mentions-self-color); 14 - border: 0; 8 + background-color: $services.mentions.selfMentionsColor; 15 15 } 16 16 17 17 .xwiki-mention.removed {
- XWiki.WikiMacroClass[0]
-
- Macro code
-
... ... @@ -11,8 +11,8 @@ 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.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) 16 16 </a> 17 17 {{/html}} 18 18 {{/velocity}} - Default category
-
... ... @@ -1,0 +1,1 @@ 1 +Notifications - Default categories
-
... ... @@ -1,1 +1,0 @@ 1 -Notifications