autoUpdateElement 设置为 false 仍会更新文本区域
autoUpdateElement set to false still updates the textarea
我正在尝试将 ckeditor 配置为不更改原始元素 (textarea) 中的任何内容,除非用户在加载编辑器后明确进行更改。我将 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());
});
我发现做我想做的唯一方法是自己存储原始信息 (.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());
});
我正在尝试将 ckeditor 配置为不更改原始元素 (textarea) 中的任何内容,除非用户在加载编辑器后明确进行更改。我将 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());
});
我发现做我想做的唯一方法是自己存储原始信息 (.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());
});