Inserting multiple smileys could spawn more whitespaces than necessary
authorAlexander Ebert <ebert@woltlab.com>
Mon, 27 Apr 2015 11:42:42 +0000 (13:42 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 27 Apr 2015 11:42:42 +0000 (13:42 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js

index e9a5ec7459ffc2c52013ec23653bc26f196a8c5d..3486a997c90aef736c0fd539ca916b6e8c44152a 100644 (file)
@@ -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 {