Jquery, ajax and CKEditor - how to untie a CKEditor instance

Hey, I use jquery, ajax and CKEditor:

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

When you first load the page through ajax it ckeditor()starts without a hitch. The second time he fails. Usually when binding, you do something like:

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

What should I do to untie it ckeditor()?

+3
source share
4 answers

The best I have found is ...

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

You can get a reference to the CKEDITOR object using:

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

and then you can destroy it like this:

CKEDITOR.remove(editor);
+3
source

I have come a long way :). You can count the number 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); 
}
+2
source

A simple way to Get instances by name, if they exist, then delete:

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

OR

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

Source: https://habr.com/ru/post/1785099/


All Articles