[BUGFIX] RTE: In Chrome RTE inserts weird span tags 91/33391/4
authorStanislas Rolland <typo3@sjbr.ca>
Wed, 22 Oct 2014 22:32:04 +0000 (18:32 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Wed, 22 Oct 2014 22:39:45 +0000 (00:39 +0200)
Remove the span tags inserted by Chrome or Opera on execution of
native execCommand. The attributes of these span tags have evolved...

Releases: master, 6.2
Resolves: #52470
Change-Id: Ibb046b86e869bd7d4afc61ab5005595467b288cd
Reviewed-on: http://review.typo3.org/33391
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
typo3/sysext/rtehtmlarea/htmlarea/DOM/HTMLArea.DOM.Node.js
typo3/sysext/rtehtmlarea/htmlarea/plugins/BlockElements/block-elements.js
typo3/sysext/rtehtmlarea/htmlarea/plugins/CopyPaste/copy-paste.js

index 94bcca4..11f3b9e 100644 (file)
@@ -163,7 +163,7 @@ HTMLArea.DOM.Node = Ext.extend(HTMLArea.DOM.Node, {
                }
                return position;
        },
-       /*
+       /**
         * Clean Apple wrapping span and font elements under the specified node
         *
         * @param       object          node: the node in the subtree of which cleaning is performed
@@ -171,24 +171,26 @@ HTMLArea.DOM.Node = Ext.extend(HTMLArea.DOM.Node, {
         * @return      void
         */
        cleanAppleStyleSpans: function (node) {
-               if (Ext.isWebKit) {
+               if (Ext.isWebKit || Ext.isOpera) {
                        if (node.getElementsByClassName) {
                                var spans = node.getElementsByClassName('Apple-style-span');
                                for (var i = spans.length; --i >= 0;) {
                                        this.removeMarkup(spans[i]);
                                }
-                       } else {
-                               var spans = node.getElementsByTagName('span');
-                               for (var i = spans.length; --i >= 0;) {
-                                       if (HTMLArea.DOM.hasClass(spans[i], 'Apple-style-span')) {
-                                               this.removeMarkup(spans[i]);
-                                       }
+                       }
+                       var spans = node.getElementsByTagName('span');
+                       for (var i = spans.length; --i >= 0;) {
+                               if (HTMLArea.DOM.hasClass(spans[i], 'Apple-style-span')) {
+                                       this.removeMarkup(spans[i]);
                                }
-                               var fonts = node.getElementsByTagName('font');
-                               for (i = fonts.length; --i >= 0;) {
-                                       if (HTMLArea.DOM.hasClass(fonts[i], 'Apple-style-span')) {
-                                               this.removeMarkup(fonts[i]);
-                                       }
+                               if (spans[i].style.cssText.indexOf('line-height') !== -1) {
+                                       this.removeMarkup(spans[i]);
+                               }
+                       }
+                       var fonts = node.getElementsByTagName('font');
+                       for (i = fonts.length; --i >= 0;) {
+                               if (HTMLArea.DOM.hasClass(fonts[i], 'Apple-style-span')) {
+                                       this.removeMarkup(fonts[i]);
                                }
                        }
                }
index 1b8174e..939c1d7 100644 (file)
@@ -698,7 +698,7 @@ HTMLArea.BlockElements = Ext.extend(HTMLArea.Plugin, {
                        } catch(e) {
                                this.appendToLog('onButtonPress', e + '\n\nby execCommand(' + buttonId + ');', 'error');
                        }
-                       if (Ext.isWebKit) {
+                       if (Ext.isWebKit || Ext.isOpera) {
                                this.editor.getDomNode().cleanAppleStyleSpans(parentNode);
                        }
                }
index 66f4394..008ca2c 100644 (file)
@@ -212,10 +212,12 @@ HTMLArea.CopyPaste = Ext.extend(HTMLArea.Plugin, {
                                }
                        }
                }
-               if (Ext.isWebKit) {
-                               // Remove Apple's span and font tags
+               if (Ext.isWebKit || Ext.isOpera) {
+                       // Remove Apple's span and font tags
                        this.editor.getDomNode().cleanAppleStyleSpans(this.editor.document.body);
-                               // Reset Safari selection in order to prevent insertion of span and/or font tags on next text input
+               }
+               if (Ext.isWebKit) {
+                       // Reset Safari selection in order to prevent insertion of span and/or font tags on next text input
                        var bookmark = this.editor.getBookMark().get(this.editor.getSelection().createRange());
                        this.editor.getSelection().selectRange(this.editor.getBookMark().moveTo(bookmark));
                }