Paolo Carrara
Paolo Carrara

Reputation: 394

Plugin with multiple commands in ckeditor

I want to know how to create a ckeditor(v4.x) plugin with two or more commands inside it.

I'm able to create and execute a ckeditor with one command, as the code can be saw below:

CKEDITOR.plugins.add ('family',
{
    init: function (editor)
    {
        editor.setKeystroke (CKEDITOR.CTRL + 65, 'parent'); // CTRL+A
        editor.addCommand ('parent',
        {
            exec : function(editor)
            {
                var selection = editor.getSelection ().getSelectedText ();
                editor.insertHtml ('<span data-role="parent">' + selection + '</span>' );
            }
        });
    }
} );

What I want to achieve:

CKEDITOR.plugins.add ('family',
{
    init: function (editor)
    {
        editor.setKeystroke (CKEDITOR.CTRL + 65, 'parent'); // CTRL+A
        editor.addCommand ('parent',
        {
            exec : function(editor)
            {
                var selection = editor.getSelection ().getSelectedText ();
                editor.insertHtml ('<span data-role="parent">' + selection + '</span>' );
            }
        });
        editor.setKeystroke (CKEDITOR.CTRL + 69, 'child'); // CTRL+E
        editor.addCommand ('child',
        {
            exec : function (editor)
            {
                var selection = editor.getSelection ().getSelectedText ();
                editor.insertHtml ('<span data-role="child">' + selection + '</span>' );
            }
        });
    }
} );

Suggestions?

Upvotes: 0

Views: 299

Answers (1)

Paolo Carrara
Paolo Carrara

Reputation: 394

I made a mistake in my tests to verify if the plugin was or not working. The mistake made it looks like it wasn't when it was.

This way of inserting two commands to one plugin does really work.

Upvotes: 1

Related Questions