I have been using CKEditor as part of an OpenCart installation and I have been searching without success to find a way to either control the order of attributes, or disable CKEditor reordering attributes.
I have attempted to disable CKEditor reordering attributes by adding this code:
CKEDITOR.on('instanceReady', function (ev) {
ev.editor.dataProcessor.writer.sortAttributes = false;
});
This does seem to have some effect by not separating similar attributes, such as image width and height tags, or alt and title tags etc. However, some attributes are still reordered.
I would like the output for an image to be (width, height, src, alt):
<img width="150" height="150" src="/image.jpg" alt="Example" />
Instead of (alt, height, width. src):
<img alt="Example" height="150" width="150" src="/image.jpg" />
Is there a way I can modify or control this behaviour?
Admittedly, I may have overlooked a suitable answer as my knowledge with JavaScript is quite limited. Please accept my apology if this has been answered elsewhere. If this is the case, please feel free to direct me to this solution.
Just to follow up on this.
Just to follow up on this. Would anyone at least be able to assist in pointing out which section of code is responsible for setting the order of the width and height attributes. CKEditor orders this with height first and then width. However, it is common practice to declare width before height.
I don't mind editing the source code but would really appreciate help in finding the correct section of code (for CKEditor 4).
Ok, bugged one of the devs...
Ok, bugged one of the devs... Here's what he said: "To change this you will need to modify CKEditor's code. You can either override the entire CKEDITOR.htmlParser.element.prototype.writeHtml function (that can be done without tinkering with the source code). Or you can override only this function, but this can be done only by source code modification." - Reinmar
Customer and Community Manager, CKSource
Follow us on: Facebook, Twitter, LinkedIn
If you think you found a bug in CKEditor, read this!
Thank you so much for looking
Thank you so much for looking into this. As you can see, I have been quite patient (initial post was made over 1 year ago) but this has been bugging me for quite some time.
My development skills are only intermediate, so I may need a little more information to make the correct changes. Looking over the source for the CKEditor package provided with OpenCart, I am unable to find the section you have referenced.
http://demo.opencart.com/admin/view/javascript/ckeditor/ckeditor.js
For the alternative solution you offered, how would I override the CKEDITOR.htmlParser.element.prototype.writeHtml function?
Thanks for the info
Thanks for the info sebstefanov.. Helped me a good bit.