| ... |
... |
@@ -97,19 +97,35 @@ |
| 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 |
+ // 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 |
+ }); |
| 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); |
|
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 |
+ } |
| 112 |
112 |
}); |
| 113 |
|
- }); |
|
129 |
+ } |
| 114 |
114 |
}); |
| 115 |
115 |
}); |