The base interface for CKEditor plugins.
In its minimal form a plugin can be a simple function that accepts the editor
as a parameter:
// A simple plugin that enables a data processor.
function MyPlugin( editor ) {
editor.data.processor = new MyDataProcessor();
}
In most cases however, you will want to inherit from the Plugin
class which implements the
Observable
and is, therefore, more convenient:
class MyPlugin extends Plugin {
init() {
// `listenTo()` and `editor` are available thanks to `Plugin`.
// By using `listenTo()` you will ensure that the listener is removed when
// the plugin is destroyed.
this.listenTo( this.editor.data, 'ready', () => {
// Do something when the data is ready.
} );
}
}
The plugin class can have pluginName
and requires
static members. See PluginStaticMembers
for more details.
The plugin can also implement methods (e.g. init()
or
destroy()
) which, when present, will be used to properly
initialize and destroy the plugin.
Note: When defined as a plain function, the plugin acts as a constructor and will be
called in parallel with other plugins' constructors.
This means the code of that plugin will be executed before init()
and
afterInit()
methods of other plugins and, for instance,
you cannot use it to extend other plugins' schema
rules as they are defined later on during the init()
stage.