Reputation: 5157
I have a CMS system that displays two CKEditors side by side so that the user can edit the main body and sidebar content. Both editors share the same toolbar.
I have added a plugin to allow users to add embedded data into the editor. The only problem is I need the data to show on the currently selected editor, where the keyboard cursor is currently setting.
How do I use javascript or JQuery to get the CKEditor element that is currently selected before the button in pressed on the toolbar.
Right now I can only get it to work by directly selecting a specific editor instance.
CKEDITOR.instances.mtxDescription.insertHtml(data);
However I need to be able to have the data drop directly into whichever editor is selected
Upvotes: 1
Views: 1178
Reputation: 5157
I was able to solve this issue by adding a blur event to each editor and storing the last id of the last time the event was called.
var currentEditorInstance = 'mtxDescription';
for(name in CKEDITOR.instances) {
CKEDITOR.instances[name].on('blur', function () {
currentEditorInstance = this.name;
});
}
Upvotes: 0
Reputation: 12690
If you're creating a CKEditor plugin, then you already have a reference to the editor that it's active, check the basic tutorial about how to create a CKEditor plugin http://docs.cksource.com/CKEditor_3.x/Tutorials/Timestamp_Plugin
editor.addCommand( 'insertTimestamp',
{
exec : function( editor )
{
var timestamp = new Date();
editor.insertHtml( 'The current date and time is: <em>' + timestamp.toString() + '</em>' );
}
});
Upvotes: 1
Reputation: 61063
I'd put a class on the editor wrapper at some level where unique IDs exist, then something like:
var myEditor = $(this).closest('.my-class').attr('id');
Upvotes: 0