Search code examples
javascriptckeditorckeditor4.x

Action fired on multiple events


In CKEditor 4 I want to fire some action on key and paste events. I've got working code for single event:

 $('#some_id').ckeditor({
     some: config
 }).ckeditor().editor.on('key', function(evt) {
    //some action here
});

And I don't want to repeat all code for next event. I've searched ckeditor docs - and it says that on method takes only string, so give it an array of events isn't possible. I've tried pass multiple events as string key, paste - it wasn't best idea. Another way could be made an array of events and iterate it with code above - this solution seems to be not ideal, but the best I can figure out for now. Have You any better ideas for this problem?


Solution

  • Since nobody have any idea in this matter, I finished with best solution I could figure out on this moment: provide array of events and iterate it. I paste here my solution for others facing same dillema:

    var editor = $('#textarea').ckeditor({
                    //some:config
                }).ckeditor().editor;
    var events = ['event1', 'event2'];
    
    for (event of events) {
        editor.on(event, function(evt) {
           //Yours actions
        }
    }