我正在尝试将ckeditor配置为不更改原始元素(textarea)中的ANYTHING,除非用户在加载编辑器后显式进行更改。我将autoUpdateElement设置为false但是一旦触发了instanceReady事件,textarea就已被修改。
例如: 如果我有,然后加载ckeditor,它会自动将元素更改为小写()。
我知道在视觉上它并不重要,但我正在尝试对其进行配置,以便所有原始内容完全保持不变。
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 * This will remove from <p> </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());
});
答案 0 :(得分: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 * This will remove from <p> </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());
});