jquery, ajax and CKEditor - how to "unbind" a CKEditor instance
Hey, I'm usin开发者_如何学Gog 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()
?
Best I've found is ...
if (CKEDITOR.instances['ckeditor']) {
CKEDITOR.remove(CKEDITOR.instances['ckeditor']);
}
You can get a CKEDITOR object reference by using:
var editor = $('.ckeditor').ckeditorGet();
and then you can destory it like this:
CKEDITOR.remove(editor);
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);
}
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);
}
精彩评论