Getting current instance of Inline CKEditor in plugin command

We recently moved away from tinymce and the custom function we created was a toolbar button that, when clicked, placed the custom div right above the toolbar that was added to the toolbar on page load.

The problem now does the same for CKEditor when using the Inline version. Since there are multiple instances at one point, how can I get an instance of the current popup inline Ckeditor so that I can add it using jQuery after clicking the custom plugin button?

Using the latest 4.x version of CKEditor.

+3


source to share


4 answers


It is difficult to imagine what you are trying to achieve. Either way, you can observe which instance of the editor is focused (you may end up storing the reference in some variable):

CKEDITOR.on( 'instanceReady', function( event ) {
    event.editor.on( 'focus', function() {
        console.log( 'focused', this );
    });
});

      



After all, you can also view the editor instances as they are stored in an object CKEDITOR.instances

in the global namespace. That being said, you can find your instance by name, id, whatever (i.e. previously associated with your button).

+7


source


I would do it like this:



    var ck_instance_name = false;
    for ( var ck_instance in CKEDITOR.instances ){
        if (CKEDITOR.instances[ck_instance].focusManager.hasFocus){
            ck_instance_name = ck_instance;
            return ck_instance_name;
        }
    }

      

+2


source


Get the current instance of the ck editor. Here is a simple code

var currentEditor;    
 for(var id in CKEDITOR.instances) {
  CKEDITOR.instances[id].on('focus', function(e) {
    // Fill some global var here
    currentEditor = e.editor.name;
});
}

      

+1


source


Using the accepted answer above, I found that the editor "name" (as you know) of the editor instance that invoked the given plugin is accessible via this._.editor.name (using CKEditor v4.3)

So you can get the content of the editor this way.

CKEDITOR.instances[this._.editor.name].getData();

      

0


source







All Articles