Skip to content

Commit

Permalink
Dynamically load plugins
Browse files Browse the repository at this point in the history
With the new installation format of CKEditor plugins are no longer
unwrapped automatically when CKEditor is instantiated. Instead now
we are responsible for loading plugins or extraPlugins and providing
a reference to the loaded class.
  • Loading branch information
craigkai committed Jan 22, 2025
1 parent 1219bf5 commit 6438897
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,33 @@ async function ReplaceAllTextareas(elt) {

// Customize shouldNotGroupWhenFull based on textarea width
const initArgs = JSON.parse(JSON.stringify(RT.Config.MessageBoxRichTextInitArguments));
initArgs.toolbar.shouldNotGroupWhenFull = textArea.offsetWidth >= 600 ? true : false;
initArgs.toolbar.shouldNotGroupWhenFull = textArea.offsetWidth >= 600;

// Load core plugins from CKEDITOR
const corePlugins = [];
for (const plugin of initArgs.plugins || []) {
if (CKEDITOR?.[plugin]) {
corePlugins.push(CKEDITOR[plugin]);
} else {
console.error(`Core CKEditor plugin "${plugin}" not found.`);
}
}

// Load extra (third-party) plugins from window
const thirdPartyPlugins = [];
for (const plugin of initArgs.extraPlugins || []) {
if (window[plugin]?.[plugin]) {
thirdPartyPlugins.push(window[plugin][plugin]);
} else {
console.error(`Third-party CKEditor plugin "${plugin}" not found.`);
}
}

// Combine core and third-party plugins
initArgs.plugins = [...corePlugins, ...thirdPartyPlugins];
initArgs.extraPlugins = []; // Clear extraPlugins as they're now included

ClassicEditor
CKEDITOR.ClassicEditor
.create( textArea, initArgs )
.then(editor => {
CKEDITORINSTANCES.instances[editor.sourceElement.name] = editor;
Expand Down

0 comments on commit 6438897

Please sign in to comment.