开发者

Update editor content immediately before save in CKEditor plug-in

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开发者_StackOverflow社区't appear to be. Does anyone know of a way of doing this?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜