Categories
Javascript

CKEditor – events like onComplete

Currently I develop a CMS in Java using Seam and JSF. Target of the CMS is a simple CMS-Structure which can easily be added to a existing Seam-Application and then provide the editable content via simple JSF-Components. Maybe I will later write some more informations about this CMS.

To easily edit text-content I include the Javascript RTE-Texteditor CKEditor. This editor transform a simple Textarea into a full featured RTE-Editor. The simple include-code looks like:

?View Code JAVASCRIPT
1
CKEditor.replace('idoftextarea');

But you can also define some configuration properties. Especially the events are not fully documented yet for version 3.0. A really interesting event is the onComplete-event or other called the instanceReady-event. This event is called if the editor is fully loaded.

A sample definition could be:

?View Code JAVASCRIPT
1
2
3
4
5
6
7
CKEditor.replace('idoftextarea', {
    on: {
        instanceReady: function(ev) { 
            window.alert('I am ready loaded'); 
        }
    }
});

A use case for such an event could be automatic resize of the editor, for example maximize.
You can also define a global event for every CKEDITOR-instance in this way:

?View Code JAVASCRIPT
1
2
3
CKEDITOR.on( 'idoftextarea', function( ev ) {
    window.alert('Im a ready loaded');
});