jodit
jodit copied to clipboard
dropdown list to insert text in editor
I have created these 2 buttons to insert some text into the editor... that is working 100%. I need to add more buttons and instead of having an icon for each of them, i would like to place them in a dropdown list. How can I achieve that?
var editor = new Jodit('#editor', {
buttons: [
{
iconURL: '/public/icons/image_left.png',
exec: function (editor) {
editor.selection.insertHTML('...');
}
},
{
iconURL: '/public/icons/image_right.png',
exec: function (editor) {
editor.selection.insertHTML('...');
}
}]
});
var editor = new Jodit('#editor', {
buttons: [
iconURL: '/public/icons/image_left.png',
list: {
first: 'first',
second: 'second'
},
childTemplate: (editor, key: string, value: string) => {
return `<span>${key}</span>`;
}
exec: function (editor, t, {control}) {
editor.selection.insertHTML(control.args);
}
]
});
Thank you!
exec: function (editor, t, {control}) { editor.selection.insertHTML(control.args); }
Thanks! I was struggling with this.
The documentation at https://xdsoft.net/jodit/pro/docs/how-to/add-custom-button.md#drop-down-list seems to be incorrect. In the example there:
exec(editor) {
let value = control.args && control.args[0]; // h1, h2 ...
control isn't received as an argument, therefore it's undefined here, and this line raises an error!