Roy Tang
Roy Tang

Reputation: 5761

Adding event handlers globally to all CKEditor instances

I want to add focus and blur handlers to all CKEditor instances in our web application. I would like to add the handlers in one place, instead of hunting down every part where we instantiate a CKEditor. Can this be done, like maybe in the config.js editorConfig setup?

I can't do something like "on document ready, add handlers to all CKEditor instances on the page" either, since additional editor instances may be created dynamically.

Upvotes: 7

Views: 1794

Answers (1)

Roy Tang
Roy Tang

Reputation: 5761

It's embarrassing when you post a question to stackoverflow then figure out the answer a few minutes later =/

Answer for posterity: We can use CKEDITOR.on("instanceReady", ...) to fire whenever a new editor is created and add our custom handlers there, example:

CKEDITOR.on("instanceReady", function(ev) {
  var editor = ev.editor;
  editor.on("focus", function(ev) {
    alert("focused!");
  });
});

Upvotes: 15

Related Questions