I am developing a plug-in for CKEditor that needs to make some changes to the editor's content immediately before saving. In FCKeditor, I achieved this using the OnAfterLinkedFieldUpdate
event but I haven't yet been able to find an equivalent way of doing this in CKEditor. I had hoped there would be a suitable event to hook into but there doesn't appear to be. Does anyone know of a way of doing this?
8
votes
2 Answers
6
votes
You could use the getData event, but be careful because it's fired also for internal uses.
I've filed http://dev.fckeditor.net/ticket/5254 to recreate the previous event
1
votes
As the link above doesn't really have the solution on substitude OnAfterLinkedFieldUpdate event I have writen a short post on how to go around it.
Here is the form:
<form id="my_form" action="submit.php" method="post" name="my_form">
<textarea id="my_text" name="my_text"></textarea>
<input id="submitForm" type="submit" name="submitForm" value="Submit" />
</form>
JavaScript:
var formSubmitted = false;
$("#submitForm").live('click', function(event) {
if (formSubmitted === true) {
formSubmitted = false;
return;
}
event.preventDefault();
//put here function to edit content == OnAfterLinkedFieldUpdate
var editor = CKEDITOR.instances.my_text;
var html = editor.getData();
html.replace(searchvalue, newvalue);
editor.setData(html);
formSubmitted = true;
$(this).trigger('click');
});
The code is here
save
event/function are you using? The "save" button? – Pekkasubmit
event handler to the form containing the editor, but this hardly qualifies as clean. – Tim Down