[BUGFIX] htmlArea RTE: Some attributes wrongly unset by "Edit element"
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 26 Jan 2012 15:37:07 +0000 (10:37 -0500)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 26 Jan 2012 16:32:06 +0000 (17:32 +0100)
The style, lang and dir attributes may be incorrect after unsetting
using "Edit element" dialogue.

Change-Id: I1c52ff8496b0ecbcb8282c6bea2c216bbab308ab
Resolves: #33466
Releases: 4.5, 4.6, 4.7
Reviewed-on: http://review.typo3.org/8712
Reviewed-by: Stanislas Rolland
Tested-by: Stanislas Rolland
typo3/sysext/rtehtmlarea/htmlarea/plugins/EditElement/edit-element.js
typo3/sysext/rtehtmlarea/htmlarea/plugins/Language/language.js
typo3/sysext/rtehtmlarea/htmlarea/plugins/TextStyle/text-style.js

index 5b131ca..9a1f84e 100644 (file)
@@ -430,24 +430,32 @@ HTMLArea.EditElement = Ext.extend(HTMLArea.Plugin, {
                this.restoreSelection();
                var textFields = this.dialog.findByType('textfield');
                Ext.each(textFields, function (field) {
-                       this.element.setAttribute(field.getItemId(), field.getValue());
+                       if (field.getXType() !== 'combo') {
+                               this.element.setAttribute(field.getItemId(), field.getValue());
+                       }
                }, this);
                var comboFields = this.dialog.findByType('combo');
+               var languageCombo = this.dialog.find('itemId', 'lang')[0];
                Ext.each(comboFields, function (field) {
                        var itemId = field.getItemId();
                        var value = field.getValue();
                        switch (itemId) {
                                case 'className':
-                                       this.stylePlugin.applyClassChange(this.element, value);
-                                       break;
-                               case 'lang':
-                                       this.getPluginInstance('Language').setLanguageAttributes(this.element, value);
+                                       if (HTMLArea.isBlockElement(this.element)) {
+                                               this.stylePlugin.applyClassChange(this.element, value);
+                                       } else {
+                                                       // Do not remove the span element if the language attribute is to be removed
+                                               this.stylePlugin.applyClassChange(this.element, value, languageCombo && (languageCombo.getValue() === 'none'));
+                                       }
                                        break;
                                case 'dir':
                                        this.element.setAttribute(itemId, (value == 'not set') ? '' : value);
                                        break;
                        }
                }, this);
+               if (languageCombo) {
+                       this.getPluginInstance('Language').setLanguageAttributes(this.element, languageCombo.getValue());
+               }
                this.close();
                event.stopEvent();
        },
index 827e52a..84b2b7d 100644 (file)
@@ -294,27 +294,29 @@ HTMLArea.Language = Ext.extend(HTMLArea.Plugin, {
         *
         * @return      void
         */
-       setLanguageAttributes : function (element, language) {
-               if (language == "none") {
-                               // Remove language mark, if any
-                       element.removeAttribute("lang");
-                       try {
-                                       // Do not let IE7 complain
-                               element.removeAttribute("xml:lang");
-                       } catch(e) { }
-                               // Remove the span tag if it has no more attribute
-                       if ((element.nodeName.toLowerCase() == "span") && !HTMLArea.hasAllowedAttributes(element, this.allowedAttributes)) {
-                               this.editor.removeMarkup(element);
-                       }
-               } else {
-                       if (this.useAttribute.lang) {
-                               element.setAttribute("lang", language);
-                       }
-                       if (this.useAttribute.xmlLang) {
+       setLanguageAttributes: function (element, language) {
+               if (element) {
+                       if (language == 'none') {
+                                       // Remove language mark, if any
+                               element.removeAttribute('lang');
                                try {
                                                // Do not let IE7 complain
-                                       element.setAttribute("xml:lang", language);
+                                       element.removeAttribute('xml:lang');
                                } catch(e) { }
+                                       // Remove the span tag if it has no more attribute
+                               if (/^span$/i.test(element.nodeName) && !HTMLArea.hasAllowedAttributes(element, this.allowedAttributes)) {
+                                       this.editor.removeMarkup(element);
+                               }
+                       } else {
+                               if (this.useAttribute.lang) {
+                                       element.setAttribute('lang', language);
+                               }
+                               if (this.useAttribute.xmlLang) {
+                                       try {
+                                                       // Do not let IE7 complain
+                                               element.setAttribute('xml:lang', language);
+                                       } catch(e) { }
+                               }
                        }
                }
        },
index ca649f7..aac787b 100644 (file)
@@ -190,8 +190,14 @@ HTMLArea.TextStyle = Ext.extend(HTMLArea.Plugin, {
        },
        /*
         * This function applies the class change to the node
+        *
+        * @param       object  node: the node on which to apply the class change
+        * @param       string  className: the class to add, 'none' to remove the last class added to the class attribute
+        * @param       boolean noRemove: true not to remove a span element with no more attribute
+        *
+        * @return      void
         */
-       applyClassChange: function (node, className) {
+       applyClassChange: function (node, className, noRemove) {
                        // Add or remove class
                if (node && !HTMLArea.isBlockElement(node)) {
                        if (className === 'none' && node.className && /\S/.test(node.className)) {
@@ -202,7 +208,7 @@ HTMLArea.TextStyle = Ext.extend(HTMLArea.Plugin, {
                                HTMLArea.DOM.addClass(node, className);
                        }
                                // Remove the span tag if it has no more attribute
-                       if (/^span$/i.test(node.nodeName) && !HTMLArea.hasAllowedAttributes(node, this.allowedAttributes)) {
+                       if (/^span$/i.test(node.nodeName) && !HTMLArea.hasAllowedAttributes(node, this.allowedAttributes) && !noRemove) {
                                this.editor.removeMarkup(node);
                        }
                }