From: Alexander Ebert Date: Mon, 27 Apr 2015 11:42:42 +0000 (+0200) Subject: Inserting multiple smileys could spawn more whitespaces than necessary X-Git-Tag: 2.1.4~42^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=030e5acdc1e14897a79d319370204d7b0e5c99e3;p=GitHub%2FWoltLab%2FWCF.git Inserting multiple smileys could spawn more whitespaces than necessary --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index e9a5ec7459..3486a997c9 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -227,17 +227,33 @@ RedactorPlugins.wbbcode = function() { } } + var $isSpace = function(sibling) { + if (sibling === null) return false; + + if ((sibling.nodeType === Node.ELEMENT_NODE && sibling.nodeName === 'SPAN') || sibling.nodeType === Node.TEXT_NODE) { + if (sibling.textContent === "\u00A0") { + return true; + } + } + + return false; + }; + // add spaces as paddings var $parent = $smiley.parentElement; - var $node = document.createTextNode('\u00A0'); - $parent.insertBefore($node, $smiley); - - var $node = document.createTextNode('\u00A0'); - if ($parent.lastChild === $smiley) { - $parent.appendChild($node); + if (!$isSpace($smiley.previousSibling)) { + var $node = document.createTextNode('\u00A0'); + $parent.insertBefore($node, $smiley); } - else { - $parent.insertBefore($node, $smiley.nextSibling); + + if (!$isSpace($smiley.nextSibling)) { + var $node = document.createTextNode('\u00A0'); + if ($parent.lastChild === $smiley) { + $parent.appendChild($node); + } + else { + $parent.insertBefore($node, $smiley.nextSibling); + } } } else {