Update editor content immediately before save in CKEditor plug-in

后端 未结 2 1034
太阳男子
太阳男子 2020-12-20 17:18

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 OnAf

相关标签:
2条回答
  • 2020-12-20 17:28

    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 讨论(0)
  • 2020-12-20 17:33

    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

    0 讨论(0)
提交回复
热议问题