简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM