emachine
emachine

Reputation: 1163

jquery, ajax and CKEditor - how to "unbind" a CKEditor instance

Hey, I'm using jquery, ajax and CKEditor:

$( '.ckeditor' ).ckeditor();

The first time the page is loaded through ajax the ckeditor() is fired off without a hitch. The second time it fails. Normally when binding you do something like:

.unbind('click').bind('click',function{...})

What do I do to unbind ckeditor()?

Upvotes: 3

Views: 4573

Answers (4)

Govind Samrow
Govind Samrow

Reputation: 10179

Simple way Get instances by name , If exist then remove:

  var editor = CKEDITOR.instances['name'];
  if (editor) {
      editor.destroy(true);
  }

OR

  var editor = CKEDITOR.instances['name'];
  if (editor) {
      CKEDITOR.remove(editor);
  }

Upvotes: 0

designosis
designosis

Reputation: 5263

Best I've found is ...

if (CKEDITOR.instances['ckeditor']) {
    CKEDITOR.remove(CKEDITOR.instances['ckeditor']);
}

Upvotes: 5

Cyrill
Cyrill

Reputation: 21

I did it long way :). You may count the amount of CK instances this way:

function countProps(obj) {
    var l = 0;
    for (p in obj) l++;
    return l;
}
if ( countProps(CKEDITOR.instances) ) { 
// to assure you have at least one instance of ckeditor
// you may want to use more complicated checks - in my case I have only one editor 
// instance per page
    editor = $('youreditor').ckeditorGet();
    CKEDITOR.remove(editor); 
}

Upvotes: 2

Variant
Variant

Reputation: 17365

You can get a CKEDITOR object reference by using:

var editor = $('.ckeditor').ckeditorGet();

and then you can destory it like this:

CKEDITOR.remove(editor);

Upvotes: 3

Related Questions