views:

22

answers:

1

Hi,

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 disapear.

Thanks!

Yvan

+1  A: 

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;

that would be a bit cleaner.

Pekka
And how do i un-load all the instances?
Yvan JANSSENS
@Yvan I have no idea. Why do you need to do that?
Pekka
because if I accidentaly load one twice, my page gets corrupt and needs refreshing. Since my app is completely AJAX driven, that's no good.
Yvan JANSSENS
@Yvan you mean, when you initialize a textarea twice?
Pekka
The textarea gets initialized a second time, when the user requests the page again. Let's say we have a blog and a registration form. If the user visits the reg form, no problem, if the user visits the blog, no problem, but if it visits the registration form again after visiting the blog, it's a mess, since the textareas get recreated. The user should refresh the page, and then it'll work again.
Yvan JANSSENS
@Yvan I see! That's indeed tricky. Make sure you ask the question on the CKEditor forums as well, as far as I know, the developers hang around there frequently.
Pekka
@Yvan you may also want to clarify your question to point out there is some Ajax loading going on. It's hard to tell at the moment.
Pekka