Work-around for Firefox not properly inserting text in empty lines
authorAlexander Ebert <ebert@woltlab.com>
Mon, 5 Jan 2015 20:13:24 +0000 (21:13 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 5 Jan 2015 20:13:24 +0000 (21:13 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbutton.js

index a92cadf857bdac75c9367b4743b97d6a8fb58ff0..37813102a77baf08da146752f891cbb182300d28 100644 (file)
@@ -166,6 +166,14 @@ RedactorPlugins.wbutton = function() {
                                else {
                                        this.buffer.set();
                                        
+                                       if (this.utils.browser('mozilla') && !$selectedHtml.length) {
+                                               var $container = getSelection().getRangeAt(0).startContainer;
+                                               if ($container.nodeType === Node.ELEMENT_NODE && $container.tagName === 'P' && $container.innerHTML === '<br>') {
+                                                       // <br> is not removed in Firefox, instead content gets inserted afterwards creating a leading empty line
+                                                       $container.removeChild($container.children[0]);
+                                               }
+                                       }
+                                       
                                        if (this._bbcodes[buttonName].voidElement) {
                                                this.insert.html($selectedHtml + this.selection.getMarkerAsHtml() + '[' + $bbcode + ']', false);
                                        }