In CKEditor, I know that in the "normal mode", we can detect any content change using the following code:
ckeditor.on('change',function(e){
console.log("ckeditor on change");
});
But if I switch over to the source mode, the event does not fire.
How can I detect the on change event for source view?
Instead of using "change" event, the "key" event does fire on the source view.
Thanks for Kicker's hint
The CKEditor 4 documentation tells that the change event won't be fired in source mode.
The example from the documentation worked for me. It binds a listener to the mode event. That's fired when the mode changes. When it changes to source, attach a listener to the editor.
editor.on('mode', function() {
if (this.mode === 'source') {
var editable = editor.editable();
editable.attachListener(editable, 'input', function() {
// Handle changes made in the source mode.
});
}
});
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