Search code examples
ckeditorlistener

How to add a custom listener in CKEditor 4.8? editor.on is not a function


I'm trying to follow the guide of inserting a custom listener for CKEDITOR using "editor.on", inserting into ckeditor.config.js but I get

Uncaught TypeError: editor.on is not a function

I need this in order to change editor request & response to get JSON so that the uploadimage plugin can work. Any advice much appreciated.


Solution

  • I found a way to load it in the ckeditor.config.js that worked for me, but if you know a better way or are aware of any implications please correct me, thanks.

    CKEDITOR.on( 'instanceReady', function( ev ) {
    ev.editor.on // followed by the code
    } );
    

    example code for the guide above I used:

    CKEDITOR.on( 'instanceReady', function( ev ) {
    ev.editor.on( 'fileUploadRequest', function( evt ) {
    var xhr = evt.data.fileLoader.xhr;
    xhr.setRequestHeader( 'Cache-Control', 'no-cache' );
    xhr.setRequestHeader( 'X-CUSTOM', 'HEADER' );
    xhr.withCredentials = true;
    } );