Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding event handlers globally to all CKEditor instances

Tags:

ckeditor

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.

like image 453
Roy Tang Avatar asked Nov 06 '13 06:11

Roy Tang


1 Answers

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!");
  });
});
like image 150
Roy Tang Avatar answered Dec 17 '22 16:12

Roy Tang