Dropping empty <li></li> after pasting
authorAlexander Ebert <ebert@woltlab.com>
Sun, 22 Feb 2015 10:02:08 +0000 (11:02 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 22 Feb 2015 10:02:08 +0000 (11:02 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js

index 038c9304111c12ba866aec5fb50604ff350cb1f6..26311b6c0e756f86851a1ab83802bcc395d1a033 100644 (file)
@@ -934,7 +934,9 @@ RedactorPlugins.wutil = function() {
                },
                
                /**
-                * Fixes the DOM by moving all non-element children of the editor into a paragraph.
+                * Fixes the DOM after pasting:
+                *  - move all non-element children of the editor into a paragraph
+                *  - pasting lists/list-items in lists can yield empty <li></li>
                 */
                fixDOM: function() {
                        var $current = this.$editor[0].childNodes[0];
@@ -974,6 +976,17 @@ RedactorPlugins.wutil = function() {
                                        $p.append($current);
                                }
                        }
+                       
+                       var $listItems = this.$editor[0].getElementsByTagName('li');
+                       for (var $i = 0, $length = $listItems.length; $i < $length; $i++) {
+                               var $listItem = $listItems[$i];
+                               if (!$listItem.innerHTML.length) {
+                                       var $parent = $listItem.parentElement;
+                                       if ($parent.children.length > 1) {
+                                               $listItem.parentElement.removeChild($listItem);
+                                       }
+                               }
+                       }
                }
        };
 };