feder
feder

Reputation: 1795

How to retrieve the CKEDITOR.status "ready"?

In my script, I wanted to wait for the CKEDITOR to be in state ready before I let my own instructions go their way. So I consulted the CKEDITOR API and wrote the following condition:

if(CKEDITOR.status == "ready"){
 //execute my code when ready
}

However, the status never ever changes to from loaded to status. Apparently I didn even see any other state.

More task specific, I wanted to catch the moment when CKEDITOR has completed modifying the inline replacing of contenteditable="true". That's when I want to go ahead with my JS code.

Any clues?

Upvotes: 22

Views: 29325

Answers (3)

oleq
oleq

Reputation: 15895

If you want to execute your code when the API is fully loaded, use CKEDITOR.loaded event:

CKEDITOR.on( 'loaded', function( evt ) {
    // your stuff here
} );

If you want to execute your code when any new instance is ready, use CKEDITOR.instanceReady event:

CKEDITOR.on( 'instanceReady', function( evt ) {
    // your stuff here
} );

If you want to execute your code when a particular instance is ready, then use CKEDITOR.editor.instanceReady event:

CKEDITOR.replace( 'editor', {
    on: {
        instanceReady: function( evt ) {
            // your stuff here
        }
    }
} );

Upvotes: 69

feder
feder

Reputation: 1795

As @Sudhir pointed out, there is a slight difference between the direct attribute value and the instanceReady method.

  • Use the event listener if you demand to be notified when CKEDITOR has not only completed its loading process, but also has completed the entire after-processing. In particular the HTML replacement and injection.

Upvotes: 2

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100195

there's no ready status in CKEDITOR, you can use loaded like:

if ( CKEDITOR.status == 'loaded' ) {
    // The API can now be fully used.
    doSomething();
}

or use instanceReady, like:

CKEDITOR.on('instanceReady', function(evt){ 
   //ready
  //do something
});

Upvotes: 10

Related Questions