jaffa
jaffa

Reputation: 27350

How do I manage the Id/Name of a CKEditor instance?

I am creating my CKEditor on a dynamically created div. It seems that CKEDITOR.instances holds the instance with an Id of 'elementX' where X is the index of the instance created.

I want to be able to managed the name myself so I can destroy the editor when the editor is closed down.

I've tried setting the 'Name' property on the CKEDITOR using the callback function in the JQuery CKEDITOR adapter wrapper and also the config object passed into the editor, but I'm not having any luck.

Can anyone suggest a way of being able to ensure that the name CKEDITOR assigns to the editor is predictable so I can destroy it?

I'm aware that CKEditor seems to name editors normally by the element ID. However, I don't have an id on the element.

Upvotes: 5

Views: 5389

Answers (1)

Bob Luo
Bob Luo

Reputation: 49

The "instanceCreated" event is fired for every editor instance created.

CKEDITOR.on( 'instanceCreated', function ( event, data ) {
    var editor = event.editor,
    element = editor.element;
    editor.name = $(element).attr('name');
} );

Upvotes: 3

Related Questions