to bind something to an onChange event, one would write something similar to this:
CKEDITOR.on( 'currentInstance', function( ev )
{
if (CKEDITOR.instances[element_id].checkDirty()) {
unsaved_changes = true;
}
});
But... how does one unbind that that function?
The above code is part of some instantiating code that I use when creating an editor. An issue arises when I use ajax to change the page, and the CKEditor (and all other javascript variables) remain defined on the page. So, the onChange event ends up getting multiple bindings... which can cause performance issues.
The eventInfo documentation of CKEditor is missing the "removeListener" method that you can find using Firebug. I've added it now but it might take a day until it's published.
You just have to call that method on the event object, for example:
CKEDITOR.on( 'currentInstance', function( ev )
{
ev.removeListener();
if (CKEDITOR.instances[element_id].checkDirty()) {
unsaved_changes = true;
}
});
window.ckeditor=CKEDITOR.replace('ckeditor'); //create instance
var focus_action =function (){
console.log('focus');
}; /*callback must have own name*/
ckeditor.on('instanceReady',function (){
var _this=this;
this.document.on('keyup',function (){
console.log(ckeditor.checkDirty());
});
this.document.on('focus',focus_action); //bind our callback
this.document.on('blur',function (){
console.log('blur');
_this.document.removeListener('focus',focus_action); //remove our callback
//_this.document.removeAllListeners(); //remove all listeners
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With