8

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?

2
  • What save event/function are you using? The "save" button?
    – Pekka
    Feb 16, 2010 at 13:32
  • Yes. The plug-in will be used by site owners who already have CKEditor set up however they have seen fit, so I would prefer to keep my plug-in as clean as possible, which means not replacing the standard save button if possible. I've looked at the source and my best bet seems to to add a submit event handler to the form containing the editor, but this hardly qualifies as clean.
    – Tim Down
    Feb 16, 2010 at 14:13

2 Answers 2

6
+125

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

5
  • In conjunction with creating my own handler for the submit event of the form?
    – Tim Down
    Mar 2, 2010 at 17:31
  • 1
    That would be an alternate solution. In fact, that's the one that I would chose at the moment because it can be easier to handle it correctly until a proper event is generated by CKEditor (I don't really know what you want to do, so I'm guessing that it must be something complex that must be done only after updating the textarea)
    – AlfonsoML
    Mar 2, 2010 at 18:22
  • My plug-in allows a user to embed pieces of content that are stored on a different server to the main HTML content. These are represented in the editor content as placeholder images to prevent them being edited in CKEditor. Immediately before the editor saves I want to replace these placeholder images with the HTML content they represent, and when the editor loads I want convert the special HTML into placeholders (which I can do with existing events). Perhaps there's another approach I should be taking?
    – Tim Down
    Mar 4, 2010 at 17:06
  • Yes, in that case you should add your processing in a similar way to the handling of anchors or object tags: you would also want to show the HTML if they press the source button (but I guess that you might have removed that button so this isn't an issue for you). Unfortunately, I don't remember right now of a good sample about how to do that processing (FCKeditor had one such sample)
    – AlfonsoML
    Mar 4, 2010 at 23:07
  • Thanks, you've been very helpful. Actually I'd probably prefer not to have it editable in source mode but I seem to remember seeing events for switching modes in CKEditor so it should be no problem.
    – Tim Down
    Mar 5, 2010 at 18:14
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.