2

我正在尝试将 ckeditor 配置为不更改原始元素(textarea)中的任何内容,除非用户在加载编辑器后明确进行更改。我将 autoUpdateElement 设置为 false,但是一旦触发了 instanceReady 事件,textarea 就已经被修改了。

例如:如果我有然后加载ckeditor,它会自动将元素更改为小写()。

我知道在视觉上这并不重要,但我正在尝试对其进行配置,以使所有原始内容都完全不变。

JSFiddle 示例

CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR; // don't wrap everything with p tags
    CKEDITOR.config.ignoreEmptyParagraph = false; // output an empty value ('') if its content only consists of an empty paragraph.
    CKEDITOR.config.allowedContent = true; // turn off advanced content filtering
    CKEDITOR.config.fillEmptyBlocks = false; // don't add &nbsp; * This will remove &nbsp; from <p>&nbsp;</p>; set to true and it will ALWAY ADD
    CKEDITOR.config.autoUpdateElement = false; // still updating?
    CKEDITOR.on('instanceReady', function (event) {
        alert($("#item_ckeditor").val());
        // normalize has been done and the contents has been made dirty. reset to we can determine user changes
        event.editor.resetDirty();
        event.editor.execCommand('source');


    });
    $("#item_ckeditor").ckeditor();
    $("#item_docompare").on("click", function (event) {

        var $textarea = $("#item_ckeditor"),
            editor = $textarea.ckeditorGet();
        alert($textarea.val());
        if (editor.checkDirty()) // only update the textarea if something was changed
        {

            alert('updating');
            editor.updateElement();
        }

        editor.destroy();
        alert($textarea.val());

    });
4

1 回答 1

0

我发现做我想做的唯一方法是自己存储原始信息(.data(“originalvalue”))。我希望有人仍然可以回答为什么 autoupdateelement 属性在设置为 false 时仍会自动更新元素。

    CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR; // don't wrap everything with p tags
        CKEDITOR.config.ignoreEmptyParagraph = false; // output an empty value ('') if its content only consists of an empty paragraph.
        CKEDITOR.config.allowedContent = true; // turn off advanced content filtering
        CKEDITOR.config.fillEmptyBlocks = false; // don't add &nbsp; * This will remove &nbsp; from <p>&nbsp;</p>; set to true and it will ALWAY ADD
        CKEDITOR.config.autoUpdateElement = false; // still updating?
        CKEDITOR.on('instanceReady', function (event) {
            alert($("#item_ckeditor").val());
            // normalize has been done and the contents has been made dirty. reset to we can determine user changes
            event.editor.resetDirty();
            event.editor.execCommand('source');


        });
        $("#item_ckeditor").data("originalvalue", $("#item_ckeditor").val()).ckeditor();
        $("#item_docompare").on("click", function (event) {

            var $textarea = $("#item_ckeditor"),
                editor = $textarea.ckeditorGet();
            alert($textarea.val());
            if (editor.checkDirty()) // only update the textarea if something was changed
            {

                alert('updating');
                editor.updateElement();
            }
            else
                $textarea.val($textarea.data("originalvalue"));

            editor.destroy();
            alert($textarea.val());

        });
于 2015-03-11T16:30:09.003 回答