From bc878c70890942cc6a52e3348b93cacc21c70a85 Mon Sep 17 00:00:00 2001 From: Stanislas Rolland Date: Thu, 26 Jan 2012 10:37:07 -0500 Subject: [PATCH] [BUGFIX] htmlArea RTE: Some attributes wrongly unset by "Edit element" The style, lang and dir attributes may be incorrect after unsetting using "Edit element" dialogue. Change-Id: I64a34741ca0bbe77de53d5cbba649604b119a55a Resolves: #33466 Releases: 4.5, 4.6, 4.7 Reviewed-on: http://review.typo3.org/8711 Reviewed-by: Stanislas Rolland Tested-by: Stanislas Rolland --- .../plugins/EditElement/edit-element.js | 18 +++++++--- .../htmlarea/plugins/Language/language.js | 36 ++++++++++--------- .../htmlarea/plugins/TextStyle/text-style.js | 10 ++++-- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/typo3/sysext/rtehtmlarea/htmlarea/plugins/EditElement/edit-element.js b/typo3/sysext/rtehtmlarea/htmlarea/plugins/EditElement/edit-element.js index c657a164ac97..d9e4bacd7936 100644 --- a/typo3/sysext/rtehtmlarea/htmlarea/plugins/EditElement/edit-element.js +++ b/typo3/sysext/rtehtmlarea/htmlarea/plugins/EditElement/edit-element.js @@ -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.DOM.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(); }, diff --git a/typo3/sysext/rtehtmlarea/htmlarea/plugins/Language/language.js b/typo3/sysext/rtehtmlarea/htmlarea/plugins/Language/language.js index c6c50e7e6b51..929302d2314a 100644 --- a/typo3/sysext/rtehtmlarea/htmlarea/plugins/Language/language.js +++ b/typo3/sysext/rtehtmlarea/htmlarea/plugins/Language/language.js @@ -289,26 +289,28 @@ 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 (/^span$/i.test(element.nodeName) && !HTMLArea.DOM.hasAllowedAttributes(element, this.allowedAttributes)) { - this.editor.getDomNode().removeMarkup(element); - } - } else { - if (this.useAttribute.lang) { - element.setAttribute('lang', language); - } - if (this.useAttribute.xmlLang) { + 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.DOM.hasAllowedAttributes(element, this.allowedAttributes)) { + this.editor.getDomNode().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) { } + } } } }, diff --git a/typo3/sysext/rtehtmlarea/htmlarea/plugins/TextStyle/text-style.js b/typo3/sysext/rtehtmlarea/htmlarea/plugins/TextStyle/text-style.js index c11d3d858f68..d0d408b22c90 100644 --- a/typo3/sysext/rtehtmlarea/htmlarea/plugins/TextStyle/text-style.js +++ b/typo3/sysext/rtehtmlarea/htmlarea/plugins/TextStyle/text-style.js @@ -183,8 +183,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.DOM.isBlockElement(node)) { if (className === 'none' && node.className && /\S/.test(node.className)) { @@ -195,7 +201,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.DOM.hasAllowedAttributes(node, this.allowedAttributes)) { + if (/^span$/i.test(node.nodeName) && !HTMLArea.DOM.hasAllowedAttributes(node, this.allowedAttributes) && !noRemove) { this.editor.getDomNode().removeMarkup(node); } } -- 2.20.1