[BUGFIX] RTE wraps p tags around ol/ul in chrome and opera 73/33773/3
authorStanislas Rolland <typo3@sjbr.ca>
Tue, 4 Nov 2014 04:11:35 +0000 (23:11 -0500)
committerStanislas Rolland <typo3@sjbr.ca>
Tue, 4 Nov 2014 04:16:49 +0000 (05:16 +0100)
This is a follow-up to change https://review.typo3.org/#/c/33655/

Resolves: #62559
Resolves: #59559
Resolves: #52470
Releases: master, 6.2
Change-Id: I66c1ed5cf288cd8aaaac66fc12655c655ac1964c
Reviewed-on: http://review.typo3.org/33773
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
typo3/sysext/rtehtmlarea/htmlarea/plugins/BlockElements/block-elements.js

index d18dcfb..c9cc418 100644 (file)
@@ -691,24 +691,33 @@ HTMLArea.BlockElements = Ext.extend(HTMLArea.Plugin, {
                        first.innerHTML = '<br />';
                        this.editor.getSelection().selectNodeContents(first, true);
                } else {
-                       // parentElement may be removed by following command
-                       var parentNode = parentElement.parentNode;
                        try {
                                this.editor.getSelection().execCommand(buttonId, false, null);
                        } catch(e) {
                                this.appendToLog('onButtonPress', e + '\n\nby execCommand(' + buttonId + ');', 'error');
                        }
                        if (Ext.isWebKit || Ext.isOpera) {
-                               // Webkit and Opera may wrap the list inside a paragraph
-                               if (parentElement && /^(p)$/i.test(parentElement.nodeName) && parentElement.firstChild && /^(ol|ul)$/i.test(parentElement.firstChild.nodeName)) {
-                                       // Probably Chrome
+                               var parentElement = this.editor.getSelection().getParentElement();
+                               var parentNode = parentElement.parentNode;
+                               // If the parent of the selection is a span, remove it
+                               if (/^(span)$/i.test(parentElement.nodeName)) {
                                        this.editor.getDomNode().removeMarkup(parentElement);
-                               } else if (parentElement.firstChild && /^(p)$/i.test(parentElement.firstChild.nodeName) && parentElement.firstChild.firstChild && /^(ol|ul)$/i.test(parentElement.firstChild.firstChild.nodeName)) {
-                                       // Probably Opera
-                                       this.editor.getDomNode().removeMarkup(parentElement.firstChild);
+                                       parentElement = parentNode;
                                }
-                               // Webkit and Opera may pollute the list with span tags
-                               this.editor.getDomNode().cleanAppleStyleSpans(parentNode);
+                               // The list might not be well-formed
+                               while (/^(li)$/i.test(parentElement.nodeName)) {
+                                       parentElement = parentElement.parentNode;
+                               }
+                               if (/^(ol|ul)$/i.test(parentElement.nodeName)) {
+                                       // Make sure the list is well-formed
+                                       this.makeNestedList(parentElement);
+                                       // The list may be wrapped inside a paragraph
+                                       if (/^(p)$/i.test(parentElement.parentNode.nodeName)) {
+                                               this.editor.getDomNode().removeMarkup(parentElement.parentNode);
+                                       }
+                               }
+                               // Content may be polluted with span and font tags
+                               this.editor.getDomNode().cleanAppleStyleSpans(parentElement);
                        }
                }
        },
@@ -823,7 +832,7 @@ HTMLArea.BlockElements = Ext.extend(HTMLArea.Plugin, {
        },
        /*
         * Make XHTML-compliant nested list
-        * We need this for Opera
+        * We need this for Opera and Chrome
         */
        makeNestedList: function (el) {
                var previous;
@@ -832,6 +841,8 @@ HTMLArea.BlockElements = Ext.extend(HTMLArea.Plugin, {
                                for (var j = i.firstChild; j; j = j.nextSibling) {
                                        if (/^(ol|ul)$/i.test(j.nodeName)) {
                                                this.makeNestedList(j);
+                                       } else if (/^(li)$/i.test(j.nodeName)) {
+                                               this.editor.getDomNode().removeMarkup(j);
                                        }
                                }
                        } else if (/^(ol|ul)$/i.test(i.nodeName)) {