Änderungen von Dokument MentionsMacro

Zuletzt geändert von admin am 2025/02/27 21:25

Von Version 5.1
bearbeitet von admin
am 2022/04/29 18:57
Änderungskommentar: Install extension [org.xwiki.platform:xwiki-platform-mentions-ui/14.3]
Auf Version 4.1
bearbeitet von admin
am 2022/03/08 16:29
Änderungskommentar: Install extension [org.xwiki.platform:xwiki-platform-mentions-ui/14.1]

Zusammenfassung

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -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,19 +97,21 @@
97 97   };
98 98   }
99 99  
100 - function updateConfig(editor) {
101 - editor.config.mentions = editor.config.mentions || [];
102 - editor.config.mentions.push(getUserMentionsConfig(editor));
100 + function updateConf(config, name) {
101 + const newConf = config || {};
102 + newConf.mentions = newConf.mentions || [];
103 + newConf.mentions.push(confMentions(name));
104 + return newConf;
103 103   }
104 104  
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);
112 - });
113 - });
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 + };
114 114   });
115 115  });