Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen to basic events in CKEditor?

I can't figure out how to listen to focus, click, onKeyUp and other basic dom events in ckeditor. In the events summary there is only a few events regarding the lifecycle of ckeditor. And the "textArea" of ckeditor is an iframe, and it's html itself, so it is not clear on what dom node to listen.

like image 504
lisak Avatar asked Apr 19 '11 19:04

lisak


People also ask

How do I make CKEditor read only?

CKEditor 5 offers an out of the box read-only mode. The feature does not require any additional plugin and the editor can be set into a read-only mode using the editor's Editor#enableReadOnlyMode() method.

How does CKEditor show data?

1) Enclose your CKEditor in a container. 2) add if condition (DataAction. isDataFetched) in the Visible property of the container. This will only show CKEditor when you have the data.

How do I call CKEditor?

Creating editor instances At this point, any textarea, p or div element can be transformed into a rich text editor by simply using the ckeditor() method: $( 'textarea. editor' ). ckeditor();


2 Answers

It's not a big deal, just do the following, works for focus, blur, click etc.

var ckeditor = CKEDITOR.instances['textArea_id'];
ckeditor.on('focus', fnHandler, context, data, priority);

or a jQuery example :

$(document).ready(function () {
    $('#YOUR_TEXTAREA_ID').ckeditor(ckeditor_config);

    CKEDITOR.instances.YOUR_TEXTAREA_ID.on('blur', fnHandler);
});

I don't know when this support appeared, but it definitely works for 3.5.x

like image 104
lisak Avatar answered Sep 28 '22 08:09

lisak


CKEditor actually has built-in event handling in the object. See this article for an explanation: http://alfonsoml.blogspot.com/2009/09/ckeditor-events.html

So, to catch a modification in a CKEditor instance you could do this:

CKEDITOR.on('currentInstance', function(){modified = true;});

Also, it appears that version 3 has an event processor built into it that's more straightforward: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.ui.dialog.file.html#eventProcessors

CK is a bit convoluted and documentation has holes, but based on its ability to gracefully handle Word generated HTML it gets my vote as the best option out there.

like image 22
bpeterson76 Avatar answered Sep 28 '22 07:09

bpeterson76