name | String | |
button | Object |
Adds a button to the toolbar or to the control bar.
this.app.toolbar.add('mybutton', button);
this.app.extrabar.add('mybutton', button);
this.app.control.add('mybutton', button);
this.app.context.add('mybutton', button);
this.app.addbar.add('mybutton', button);
The button object can contain the parameters described below.
All the examples show the method of adding a button to the toolbar. The button object can have the same parameters to add to the control bar, context bar or addbar.
The position of the button in the toolbar or control bar.
this.app.toolbar.add('mybutton', {
title: 'My Button',
icon: '<svg...>',
command: 'myplugin.toggle',
position: 'first'
});
Add a button to the beginning of the toolbar.
position: 'first'
Add a new button after the specified button.
position: { after: 'buttonname' }
Add a new button before the specified button.
position: { before: 'buttonname' }
Adds a button only for specific blocks.
this.app.toolbar.add('mybutton', {
title: 'My Button',
icon: '<svg...>',
command: 'myplugin.toggle',
blocks: {
all: 'editable'
}
});
this.app.toolbar.add('mybutton', {
title: 'My Button',
icon: '<svg...>',
command: 'myplugin.toggle',
blocks: {
types: ['paragraph', 'heading']
}
});
Adds a button to blocks except specified in the array.
this.app.toolbar.add('mybutton', {
title: 'My Button',
icon: '<svg...>',
command: 'myplugin.toggle',
blocks: {
all: 'editable',
except: ['list']
}
});
The text that will be displayed on the icon. You can use html.
this.app.toolbar.add('mybutton', {
title: 'My Button',
icon: '<svg...>',
command: 'myplugin.toggle'
});
Icon button in HTML or SVG format.
this.app.toolbar.add('mybutton', {
title: 'My Button',
icon: '<svg...>',
command: 'myplugin.toggle'
});
A method that will check whether a button is displayed. If the button does not need to be shown on a specific condition when clicking on a block, then the method should return false
, in other cases it is necessary to return the button object.
Redactor.add('plugin', 'myplugin', {
start() {
this.app.toolbar.add('mybutton', {
title: 'My Button',
icon: '<svg...>',
command: 'myplugin.toggle',
observer: 'myplugin.observe'
});
},
observe(obj, name) {
if (somethings) {
return false;
}
return obj;
},
toggle(params, button) {
// do something
}
});
Calls the specified method when the button is clicked.
Redactor.add('plugin', 'myplugin', {
start:() {
this.app.toolbar.add('mybutton', {
title: 'My Button',
icon: '<svg...>',
command: 'myplugin.toggle'
});
},
toggle(params, button, name, e) {
// do something
}
});
The command passes the object with following values:
params
— button parametersbutton
— button instancename
— name of the buttone
— button click event object It is specified as an object and is passed as an argument when the button command is called.
Redactor.add('plugin', 'myplugin', {
start() {
this.app.toolbar.add('mybutton', {
title: 'My Button',
icon: '<svg...>',
command: 'myplugin.toggle',
params: {
arg1: value1,
arg2: value2
}
});
},
toggle(params, button, name, e) {
// get params
console.log(params.arg1, params.arg2);
}
});