Disable sorting of element attributes

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 03:01:52
CKEDITOR.on( 'instanceReady', function( ev ) {
    ev.editor.dataProcessor.writer.sortAttributes = 0;
});

will disable attribute sorting for all editor instances on the page. This is not covered anywhere in CKEditor docs and was found by reviewing editor instance object.

jnoreiga

This is what I ended up using based on Reinmar's suggestions.

jsfiddle

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

    };
CKEDITOR.on('instanceReady', function (event) {
        event.editor.initialdata = event.editor.getData();
    });

Your code does strange things like calling editor.resetDirty() on editor#contentDom (what for?). Additionally, CKEditor does not sort attributes, because the only thing that getSnapshot() does is taking the editable's innerHTML. So if anything sorts attributes it's browsers and if they do this (I remember that some do this randomly), then there's nothing you can do.

You need to start from scratch. Define first what you want to achieve and do this with least code possible. I would also advise you to not use editor.checkDirty() because it's a legacy method that won't work in specific cases (yes, this is missing in the docs). Use editor#change to get live notifications about changes, or simply compare editor.getData() from time to time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!