Search code examples
javascriptckeditor

how to run a plugin in Ckeditor without click


I'm trying to run a ckeditor plugin "showblocks" with several different approaches from question and answer but nothing work. Does anyone know how to run a plugin without click?

CKEDITOR.tools.callFunction(199, this);
CKEDITOR.instances['editor1'].execCommand('show blocks');

Solution

  • The name of the command is "showblocks", not "show blocks" (there is no space between the words).

    CKEDITOR.instances['editor1'].execCommand('showblocks');
    

    EDIT: After reading your comments, you are trying to execute showblocks automatically when ckeditor loads, but you can't do that until ckeditor fully loads and is ready for interaction. Also, the configuration option is called startupOutlineBlocks. You have 3 options.

    First option (enable showblocks globally using startupOutlineBlocks ):

    CKEDITOR.config.startupOutlineBlocks = true;
    

    Second option (enable showblocks for specific instance):

    CKEDITOR.replace('editor1', {
        startupOutlineBlocks: true
    });
    

    Third option (execute showblocks command after ckeditor fully loads using instanceReady event ):

    CKEDITOR.replace('editor1', {
        on: {
            instanceReady: function(evt) {
                this.execCommand('showblocks');
            }
        }
    });
    

    You don't need third option if you have enabled first or second option which are better anyway.