From: Alexander Ebert Date: Mon, 19 Dec 2016 12:11:45 +0000 (+0100) Subject: Fixed text alignment not preserved on paste X-Git-Tag: 3.0.0_RC_2~19 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=831834f5dfa2321e659247f7cc88b1757c9826a9;p=GitHub%2FWoltLab%2FWCF.git Fixed text alignment not preserved on paste --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js index 687ecbc4fb..26cf5ccc88 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js @@ -111,7 +111,7 @@ $.Redactor.prototype.WoltLabClean = function() { } var div = elCreate('div'); - div.innerHTML = html; + div.innerHTML = html.replace(/@@@WOLTLAB-P-ALIGN-(?:left|right|center|justify)@@@/g, ''); var element, elements = elBySelAll('[style]', div), property, removeStyles; for (var i = 0, length = elements.length; i < length; i++) { @@ -142,10 +142,15 @@ $.Redactor.prototype.WoltLabClean = function() { } }); - // Empty lines in Microsoft Word are represented with   - elBySelAll('p.MsoNormal', div, function (p) { - if (p.childElementCount === 1 && p.children[0].nodeName === 'O:P' && p.textContent === '\u00A0') { - p.innerHTML = '
'; + elBySelAll('p', div, function (p) { + if (p.classList.contains('MsoNormal')) { + // Empty lines in Microsoft Word are represented with   + if (p.childElementCount === 1 && p.children[0].nodeName === 'O:P' && p.textContent === '\u00A0') { + p.innerHTML = '
'; + } + } + else if (p.className.match(/\btext-(left|right|center|justify)\b/)) { + p.insertBefore(document.createTextNode('@@@WOLTLAB-P-ALIGN-' + RegExp.$1 + '@@@'), p.firstChild); } }); @@ -156,6 +161,13 @@ $.Redactor.prototype.WoltLabClean = function() { html = mpOnPaste.call(this, div.innerHTML, data, insert); html = html.replace(/@@@WOLTLAB-BR-MARKER@@@/g, ''); + html = html.replace(/(

)?\s*@@@WOLTLAB-P-ALIGN-(left|right|center|justify)@@@/g, function (match, p, alignment) { + if (p) { + return '

'; + } + + return ''; + }); div.innerHTML = html;