This example shows how to create a custom plugin class, register it with Redactor.addPlugin, and enable it in the editor.
<div id="entry-create-plugin"></div>
const app = Redactor('#entry-create-plugin', {
plugins: ['greeting']
});
class GreetingPlugin {
static defaultLang = {
en: {
greeting: {
title: 'Greeting',
text: 'Hello from plugin!'
}
}
};
constructor(app) {
this.app = app;
}
start() {
this.app.toolbar.add('greeting', {
title: '## greeting.title ##',
icon: '<svg ...>',
command: 'greeting.insert',
position: { after: 'add' }
});
}
insert() {
const inserter = this.app.getService('inserter');
const text = this.app.getLang('greeting.text');
inserter.insertHtml(`<p>${text}</p>`, { caret: 'end' });
}
}
Redactor.addPlugin('greeting', GreetingPlugin);