From: Alexander Ebert Date: Wed, 17 Dec 2014 00:13:44 +0000 (+0100) Subject: Fixed text nodes being direct editor childNodes breaking stuff X-Git-Tag: 2.1.0_Beta_2~20 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a427d433c8ae9c19858344709eb0380fa889b602;p=GitHub%2FWoltLab%2FWCF.git Fixed text nodes being direct editor childNodes breaking stuff --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 33411316cf..d09207e764 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -108,6 +108,7 @@ RedactorPlugins.wbbcode = function() { this.button.get('html').children('i').removeClass('fa-square').addClass('fa-square-o'); $tooltip.text(WCF.Language.get('wcf.bbcode.button.toggleBBCode')); + this.wutil.fixDOM(); $fixBR(this.$editor); this.wutil.saveSelection(); diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index b3424b15bc..b1f0afb63d 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -759,44 +759,13 @@ RedactorPlugins.wmonkeypatch = function() { * - fixes text pasting in Internet Explorer 11 (#2040) */ paste: function() { - var $fixDOM = (function() { - var $current = this.$editor[0].childNodes[0]; - var $nextSibling = $current; - var $p = null; - - while ($nextSibling) { - $current = $nextSibling; - $nextSibling = $current.nextSibling; - - if ($current.nodeType === Element.ELEMENT_NODE) { - if (this.reIsBlock.test($current.tagName)) { - $p = null; - } - else { - if ($p === null) { - $p = $('

').insertBefore($current); - } - - $p.append($current); - } - } - else if ($current.nodeType === Element.TEXT_NODE) { - if ($p === null) { - $p = $('

').insertBefore($current); - } - - $p.append($current); - } - } - }).bind(this); - // paste.insert var $mpInsert = this.paste.insert; this.paste.insert = (function(html) { $mpInsert.call(this, html); setTimeout((function() { - $fixDOM(); + this.wutil.fixDOM(); if ($.browser.msie) { getSelection().getRangeAt(0).collapse(false); diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index 9386feb203..bc92f6c084 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -758,6 +758,49 @@ RedactorPlugins.wutil = function() { var $node = $(this.opts.emptyHtml); $node[(setBefore ? 'insertBefore' : 'insertAfter')](element); this.caret.setEnd($node[0]); + }, + + /** + * Fixes the DOM by moving all non-element children of the editor into a paragraph. + */ + fixDOM: function() { + var $current = this.$editor[0].childNodes[0]; + var $nextSibling = $current; + var $p = null; + + while ($nextSibling) { + $current = $nextSibling; + $nextSibling = $current.nextSibling; + + if ($current.nodeType === Element.ELEMENT_NODE) { + if (this.reIsBlock.test($current.tagName)) { + $p = null; + } + else { + if ($p === null) { + $p = $('

').insertBefore($current); + } + + $p.append($current); + } + } + else if ($current.nodeType === Element.TEXT_NODE) { + if ($p === null) { + // check for ghost paragraphs next + if ($nextSibling) { + if ($nextSibling.nodeType === Element.ELEMENT_NODE && $nextSibling.tagName === 'P' && $nextSibling.innerHTML === '\u200B') { + var $afterNextSibling = $nextSibling.nextSibling; + this.$editor[0].removeChild($nextSibling); + $nextSibling = $afterNextSibling; + } + } + + $p = $('

').insertBefore($current); + } + + $p.append($current); + } + } } }; };