From 40854dd467ca6912103dd55202f6d1c9f3728bdb Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 20 Dec 2016 13:00:04 +0100 Subject: [PATCH] Strip links after return key in Firefox --- .../redactor2/plugins/WoltLabKeydown.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js index 97298981b9..7df1da8fd3 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js @@ -105,6 +105,45 @@ $.Redactor.prototype.WoltLabKeydown = function() { // firefox enter into inline element if (this.detect.isFirefox() && this.utils.isInline(this.keydown.parent)) { this.keydown.insertBreakLine(e); + + // WoltLab modification: strip links on return + setTimeout((function () { + var block = this.selection.block(); + var current = this.selection.inline(); + + while (current && current !== block) { + if (current.nodeName === 'A') { + // check if this is an empty link + var remove = false; + if (current.childNodes.length === 0) { + remove = true; + } + else if (current.textContent.replace(/\u200B/g, '') === '') { + remove = true; + + // check if there are only elements + elBySelAll('*', current, function (element) { + if (element.nodeName !== 'SPAN') { + remove = false; + } + }); + } + + if (remove) { + while (current.childNodes.length) { + current.parentNode.insertBefore(current.childNodes[0], current); + } + + elRemove(current); + + break; + } + } + + current = current.parentNode; + } + }).bind(this), 1); + return; } -- 2.20.1