Skip to content

Commit

Permalink
Fixed plugin documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Jan 2, 2024
1 parent 8bca717 commit 5cf3244
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions src/core/plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Plugins can be both simple functions and complex classes.
In the simplest case, it's just a function that receives a Jodit instance as input.

```js
Jodit.plugins.add('alertMyId', (jodit) => {
alert(jodit.id);
Jodit.plugins.add('alertMyId', jodit => {
alert(jodit.id);
});
```

Expand All @@ -24,41 +24,41 @@ This is usually not what you expect. You probably want the plugin to take action
The [EventEmiter](https://xdsoft.net/jodit/docs/classes/event_emitter.EventEmitter.html#root) editor will help you with this.

```js
Jodit.plugins.add('keyLogger', (jodit) => {
jodit.events.on('keydown', e => {
sendAnalytics('keydown', e.key);
});
Jodit.plugins.add('keyLogger', jodit => {
jodit.events.on('keydown', e => {
sendAnalytics('keydown', e.key);
});
});
```

As mentioned above, plugins can be more complex than just a function. A plugin can be a class:

```js
class resizeEditor {
hasStyle = true;

buttons = [
{
name: 'custom',
group: 'other'
}
];

static requires = ['enter', 'drag-and-drop'];

init(jodit: IJodit): void {
jodit.events.on('afterInit', () => {
Jodit.ns.Helpers.css(jodit.editor, {
width: 400
});
});
}

destruct() {
Jodit.ns.Helpers.css(this.jodit.editor, {
width: null
});
}
hasStyle = true;

buttons = [
{
name: 'custom',
group: 'other'
}
];

static requires = ['enter', 'drag-and-drop'];

init(jodit: IJodit): void {
jodit.events.on('afterInit', () => {
Jodit.ns.Helpers.css(jodit.editor, {
width: 400
});
});
}

destruct() {
Jodit.ns.Helpers.css(this.jodit.editor, {
width: null
});
}
}

Jodit.plugins.add('resizeEditor', resizeEditor); // Constructor, not instance
Expand All @@ -78,51 +78,51 @@ Jodit will try to load the styles along the same path as the plugin is loaded.

```typescript
export interface IPluginButton {
name: string;
group?: ButtonGroup;
position?: number;
options?: IControlType;
name: string;
group?: ButtonGroup;
position?: number;
options?: IControlType;
}

export type ButtonGroup =
| string
| 'source'
| 'font-style'
| 'script'
| 'list'
| 'indent'
| 'font'
| 'color'
| 'media'
| 'state'
| 'clipboard'
| 'insert'
| 'history'
| 'search'
| 'other'
| 'info';
| string
| 'source'
| 'font-style'
| 'script'
| 'list'
| 'indent'
| 'font'
| 'color'
| 'media'
| 'state'
| 'clipboard'
| 'insert'
| 'history'
| 'search'
| 'other'
| 'info';
```

Buttons to be automatically added to the editor's button groups.
Those. if the plugin is connected, the button will appear in the list, if not connected, it will disappear.

```js
Jodit.defaultOptions.controls.insertTime = {
icon: require('./icon.svg'),
tooltip: 'Insert Time',
exec: (editor: IJodit) => {
editor.s.insertHTML(new Date().toTimeString());
icon: require('./icon.svg'),
tooltip: 'Insert Time',
exec: (editor: IJodit) => {
editor.s.insertHTML(new Date().toTimeString());
editor.synchronizeValues(); // For history module we need to synchronize values between textarea and editor
}
}
};

class insertTimePlugin {
buttons = [
{
name: 'insertTime',
group: 'insert'
}
];
buttons = [
{
name: 'insertTime',
group: 'insert'
}
];
}

Jodit.plugins.add('insertTimePlugin', insertTimePlugin);
Expand Down Expand Up @@ -151,8 +151,8 @@ This will allow you to find out if it works correctly and if it breaks the behav

```js
Jodit.make('#editor', {
safeMode: true,
safePluginsList: ['about'],
extraPlugins: ['yourPluginDev']
safeMode: true,
safePluginsList: ['about'],
extraPlugins: ['yourPluginDev']
});
```

0 comments on commit 5cf3244

Please sign in to comment.