[BUGFIX] RTE: Tag attributes are reversed on save
authorStanislas Rolland <typo3@sjbr.ca>
Wed, 5 Oct 2011 01:07:21 +0000 (21:07 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 6 Oct 2011 12:54:29 +0000 (14:54 +0200)
Problem: When saving a content element, the order of attributes of tags
is reversed. This clutters the workspace diffs with many changes. The
problem arises in WebKit and Opera.
Solution: Reverse the order of attributes.

Change-Id: I8de914e0f10b043c106c1cacba3e17579d43e699
Resolves: #29855
Releases: 4.5, 4.6
Reviewed-on: http://review.typo3.org/5536
Reviewed-by: Markus Klein
Reviewed-by: Stanislas Rolland
Tested-by: Stanislas Rolland
typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js

index bd7cd45..54d40b5 100644 (file)
@@ -3483,7 +3483,7 @@ HTMLArea.DOM.Walker = Ext.extend(HTMLArea.DOM.Walker, {
         */
        getAttributes: function (node) {
                var attributes = node.attributes;
-               var filterededAttributes = {};
+               var filterededAttributes = [];
                var attribute, attributeName, attributeValue;
                for (var i = attributes.length; --i >= 0 ;) {
                        attribute = attributes.item(i);
@@ -3521,9 +3521,12 @@ HTMLArea.DOM.Walker = Ext.extend(HTMLArea.DOM.Walker, {
                        if (attributeName === 'id' && /^ext-gen/.test(attributeValue)) {
                                continue;
                        }
-                       filterededAttributes[attributeName] = attributeValue;
+                       filterededAttributes.push({
+                                       attributeName: attributeName,
+                                       attributeValue: attributeValue
+                       });
                }
-               return filterededAttributes;
+               return (Ext.isWebKit || Ext.isOpera) ? filterededAttributes.reverse() : filterededAttributes;
        },
        /*
         * Set opening tag for a node
@@ -3550,8 +3553,8 @@ HTMLArea.DOM.Walker = Ext.extend(HTMLArea.DOM.Walker, {
                }
                        // Normal node
                var attributes = this.getAttributes(node);
-               for (var attributeName in attributes) {
-                       html +=  ' ' + attributeName + '="' + HTMLArea.htmlEncode(attributes[attributeName]) + '"';
+               for (var i = 0, n = attributes.length; i < n; i++) {
+                       html +=  ' ' + attributes[i]['attributeName'] + '="' + HTMLArea.htmlEncode(attributes[i]['attributeValue']) + '"';
                }
                html = '<' + node.nodeName.toLowerCase() + html + (HTMLArea.RE_noClosingTag.test(node.nodeName) ? ' />' : '>');
                        // Fix orphan list elements