禁用元素属性排序

Disable sorting of element attributes

有没有办法禁用元素属性的排序,以便 checkDirty() 在 allowedContent 设置为 true 时正常工作?

属性排序示例here

<div zattribute='z' attribute='a'>simple</div

更改为

<div attribute="a" zattribute="z">simple</div>

导致 checkDirty() 调用始终 return 为真,即使用户实际上并未在 ckeditor 用户界面中进行任何更改。

您的代码做了一些奇怪的事情,比如在 editor#contentDom 上调用 editor.resetDirty()(为什么?)。此外,CKEditor 不对属性进行排序,因为 getSnapshot() 所做的唯一事情就是采用可编辑的 innerHTML。因此,如果有任何东西对属性进行排序,它就是浏览器,如果它们这样做(我记得有些人随机这样做),那么您将无能为力。

您需要从头开始。首先定义您想要实现的目标,并尽可能使用最少的代码来实现。我还建议您不要使用 editor.checkDirty(),因为它是一种在特定情况下不起作用的遗留方法(是的,文档中缺少此方法)。使用 editor#change 获取有关更改的实时通知,或者只是不时比较 editor.getData()

This 是我根据 Reinmar 的建议最终使用的。

jsfiddle

var isdirty = function(ckeditor) {
        return ckeditor.initialdata !== ckeditor.getData();

    };
CKEDITOR.on('instanceReady', function (event) {
        event.editor.initialdata = event.editor.getData();
    });
CKEDITOR.on( 'instanceReady', function( ev ) {
    ev.editor.dataProcessor.writer.sortAttributes = 0;
});

将禁用页面上所有编辑器实例的属性排序。这在 CKEditor 文档的任何地方都没有涉及,是通过查看编辑器实例对象找到的。