From b1b42cc170c7b24a6691247ab2920ae645a68143 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 2 Mar 2015 12:19:58 +0100 Subject: [PATCH] Fixed handling of empty but formatted lines --- .../js/3rdParty/redactor/plugins/wbbcode.js | 56 +++++++++++++++---- .../js/3rdParty/redactor/plugins/wutil.js | 31 ++++++++++ 2 files changed, 77 insertions(+), 10 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 42f51e7de7..952aef76f2 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -1718,17 +1718,53 @@ RedactorPlugins.wbbcode = function() { * @param object data */ _keyupCallback: function(data) { - if (data.event.which !== $.ui.keyCode.BACKSPACE && data.event.which !== $.ui.keyCode.DELETE) { - return; + switch (data.event.which) { + case $.ui.keyCode.BACKSPACE: + case $.ui.keyCode.DELETE: + // check for empty
+ this.$editor.find('blockquote').each(function(index, blockquote) { + var $blockquote = $(blockquote); + if (!$blockquote.children('header').length) { + $blockquote.remove(); + } + }); + break; + + case $.ui.keyCode.ENTER: + // fix markup for empty lines + for (var $i = 0, $length = this.$editor[0].children.length; $i < $length; $i++) { + var $child = this.$editor[0].children[$i]; + if ($child.nodeType !== Node.ELEMENT_NODE || $child.tagName !== 'P') { + // not a

element + continue; + } + + if ($child.textContent.length > 0) { + // element is non-empty + continue; + } + + if ($child.children.length > 1 || $child.children[0].tagName === 'BR') { + // element contains more than one children or it is just a
+ continue; + } + + // head all the way down to the most inner node + $child = $child.children[0]; + while ($child.children.length === 1) { + $child = $child.children[0]; + } + + // check if node has no children and it is a
+ if ($child.children.length === 0 && $child.tagName === 'BR') { + var $parent = $child.parentNode; + var $node = document.createTextNode('\u200b'); + $parent.appendChild($node); + $parent.removeChild($child); + } + } + break; } - - // check for empty

element + continue; + } + + if ($child.textContent.length > 0) { + // element is non-empty + continue; + } + + if ($child.children.length > 1 || $child.children[0].tagName === 'BR') { + // element contains more than one children or it is just a
+ continue; + } + + // head all the way down to the most inner node + $child = $child.children[0]; + while ($child.children.length === 1) { + $child = $child.children[0]; + } + + + if ($child.childNodes.length === 0 && $child.tagName !== 'BR') { + var $node = document.createTextNode('\u200b'); + $child.appendChild($node); + } + } } }; }; -- 2.20.1