mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.2 KiB
2.2 KiB
Commands
You can init the editor with all necessary commands via configuration
var editor = grapesjs.init({
...
commands: {...} // Check below for the properties
...
});
Before using methods you should get first the module from the editor instance, in this way:
var commands = editor.Commands;
Parameters
configObject Configurations
Examples
...
commands: {
defaults: [{
id: 'helloWorld',
run: function(editor, sender){
alert('Hello world!');
},
stop: function(editor, sender){
alert('Stop!');
},
}],
},
...
add
Add new command to the collection
Parameters
idstring Command's IDcommand(Object | Function) Object representing your command, By passing just a function it's intended as a stateless command (just like passing an object with onlyrunmethod).
Examples
commands.add('myCommand', {
run(editor, sender) {
alert('Hello world!');
},
stop(editor, sender) {
},
});
// As a function
commands.add('myCommand2', editor => { ... });
Returns this
get
Get command by ID
Parameters
idstring Command's ID
Examples
var myCommand = commands.get('myCommand');
myCommand.run();
Returns Object Object representing the command
has
Check if command exists
Parameters
idstring Command's ID
Returns Boolean