Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect CKEditor source mode on change event

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?

like image 399
user1431972 Avatar asked Jun 28 '13 06:06

user1431972


2 Answers

Instead of using "change" event, the "key" event does fire on the source view.

Thanks for Kicker's hint

like image 73
user1431972 Avatar answered Nov 19 '22 04:11

user1431972


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.
        });
    }
});
like image 37
Martijn Gastkemper Avatar answered Nov 19 '22 03:11

Martijn Gastkemper