Martyn
Martyn

Reputation: 6383

CKEDITOR.editor.on not working with replaceAll

I'm trying to capture an event from a plugin:

$(document).ready(function( ) {
    CKEDITOR.replaceAll( 'js-ckeditor' );

    CKEDITOR.editor.on('simpleuploads.startUpload', function (ev) {
        console.log(ev.data)
    });
});

...but when I run it, I see the error TypeError: CKEDITOR.editor.on is not a function. What am I doing wrong here? According to the documentation editor should have a method "on" (which I can see when I inspect the object). By the way, both the textarea and plugin function well so replaceAll seems to work fine.

Upvotes: 1

Views: 1993

Answers (1)

oleq
oleq

Reputation: 15895

CKEDITOR.editor.on is a method of a working editor instance, i.e. returned by CKEDITOR.replace, while CKEDITOR.editor is just editor constructor.

Instead attach CKEDITOR.instanceReady event before CKEDITOR.replaceAll and use event data to attach more events to particular editor instances:

CKEDITOR.on( 'instanceReady', function( evt ) {
    evt.editor.on( 'simpleuploads.startUpload', function( evt ) {
        ...
    } );
} );

CKEDITOR.replaceAll( 'js-ckeditor' );

Upvotes: 3

Related Questions