Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if CKEditor is loaded?

How do I find out if CKEditor is loaded? I've looked through the API docs, but could only find the loaded event. I want to check if CKEditor is loaded, because if I load it a second time, my textareas disapears.

like image 203
friedkiwi Avatar asked Aug 10 '10 10:08

friedkiwi


4 Answers

The loaded event didn't work for me. instanceReady worked:

CKEDitor_loaded = false;

CKEDITOR.on('instanceReady', function(){ CKEditor_loaded = true; }); 
like image 55
Kees C. Bakker Avatar answered Oct 06 '22 06:10

Kees C. Bakker


var waitCKEDITOR = setInterval(function() {
    if (window.CKEDITOR) {
       clearInterval(waitCKEDITOR);
       //CKEDITOR.replace(...);
    }
}, 100/*milli*/);
like image 20
Alex Avatar answered Oct 06 '22 08:10

Alex


I've looked through the API docs, but could only find the loaded event.

I don't know whether there exists a specific property for this - there might! - but you could use the loaded event to set a global flag. It's not really nice but would do the job.

// At the top of the script
CKEDitor_loaded = false;

// then later
CKEDITOR.on('loaded', function(){ CKEditor_loaded = true; });

Instead of a global variable, you could also consider setting something inside CKEDITOR:

CKEDITOR.flag_loaded = true;

This would be a bit cleaner.

like image 2
Pekka Avatar answered Oct 06 '22 06:10

Pekka


If instance is not ready, the text set would be discarded

On initialization of the CkEditor (version 4 here), you should never set any data before the editor is ready to handle it.

// Initialize this._editor with replace

if (this._editor.status !== "ready") {
    this._editor.on("instanceReady",
        event => {
            event.editor.setData(data);
        });
} else {
    this._editor.setData(data);
}
like image 1
Fab Avatar answered Oct 06 '22 06:10

Fab