From 6aa17885e02e8f0f63a6a38e83bd52f638a3fef8 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 25 Oct 2016 16:18:34 +0200 Subject: [PATCH] Working around some new bugs ;) --- com.woltlab.wcf/templates/wysiwyg.tpl | 2 - .../install/files/acp/templates/wysiwyg.tpl | 2 - .../redactor2/plugins/WoltLabClean.js | 85 +++++++++---------- .../3rdParty/redactor2/plugins/WoltLabList.js | 28 ------ 4 files changed, 40 insertions(+), 77 deletions(-) delete mode 100644 wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index d6576ff48f..2435b9a804 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -26,7 +26,6 @@ '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInsert.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}', - '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabList.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMention.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabModal.js?v={@LAST_UPDATE_TIME}', @@ -196,7 +195,6 @@ 'WoltLabInlineCode', 'WoltLabInsert', 'WoltLabLink', - 'WoltLabList', 'WoltLabModal', 'WoltLabObserve', 'WoltLabPaste', diff --git a/wcfsetup/install/files/acp/templates/wysiwyg.tpl b/wcfsetup/install/files/acp/templates/wysiwyg.tpl index d6576ff48f..2435b9a804 100644 --- a/wcfsetup/install/files/acp/templates/wysiwyg.tpl +++ b/wcfsetup/install/files/acp/templates/wysiwyg.tpl @@ -26,7 +26,6 @@ '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInsert.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}', - '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabList.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMention.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabModal.js?v={@LAST_UPDATE_TIME}', @@ -196,7 +195,6 @@ 'WoltLabInlineCode', 'WoltLabInsert', 'WoltLabLink', - 'WoltLabList', 'WoltLabModal', 'WoltLabObserve', 'WoltLabPaste', diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js index 0fe2d1766b..31cdce6da9 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js @@ -196,7 +196,7 @@ $.Redactor.prototype.WoltLabClean = function() { this.clean.convertTags = (function(html, data) { var div = elCreate('div'); div.innerHTML = html; - + console.debug(html); // reset tag storage storage = []; @@ -213,7 +213,45 @@ $.Redactor.prototype.WoltLabClean = function() { item.element.outerHTML = '###custom' + i + '###' + item.element.innerHTML + '###/custom' + i + '###'; }); - return mpConvertTags.call(this, div.innerHTML, data); + var hadLinks = false; + if (data.links && this.opts.pasteLinks) { + elBySelAll('a', div, function(link) { + if (link.href) { + link.outerHTML = '##%a href="' + link.href + '"%##' + link.innerHTML + '##%/a%##'; + } + }); + + hadLinks = true; + data.links = false; + } + + var hadImages = false; + if (data.images && this.opts.pasteImages) { + elBySelAll('img', div, function(image) { + if (image.src) { + var tmp = '##%img src="' + image.src + '"'; + var attr; + for (var j = 0, length = image.attributes.length; j < length; j++) { + attr = image.attributes.item(j); + if (attr.name !== 'src') { + tmp += ' ' + attr.name + '="' + attr.value + '"'; + } + } + + image.outerHTML = tmp + '%##'; + } + }); + + hadImages = true; + data.images = false; + } + + html = mpConvertTags.call(this, div.innerHTML, data); + + if (hadImages) data.images = true; + if (hadLinks) data.links = true; + + return html; }).bind(this); var mpReconvertTags = this.clean.reconvertTags; @@ -248,49 +286,6 @@ $.Redactor.prototype.WoltLabClean = function() { html = div.innerHTML; } - // reconvert links as the regex can be overly greedy sometimes - if (data.links) { - // prevent the original regex from being executed again - data.links = false; - - // We try to avoid the regex to consume too many parts - // by having it work from the back to the front. Please - // keep in mind that the parts are reversed, so they - // actually appear in inverted order - var tmp = html.split(/(###\/a###)/gi).reverse(); - var part, nextPart; - for (var i = 1, length = tmp.length; i < length; i++) { - if (i + 1 === length) { - break; - } - - part = tmp[i]; - nextPart = tmp[i + 1]; - - // split by '###a' to find all possible start positions - var anchors = nextPart.split(/(###a)/gi).reverse(); - var composite; - for (var j = 1, innerLength = anchors.length; j < innerLength; j++) { - if (j + 1 === innerLength) { - break; - } - - composite = anchors[j] + anchors[j - 1]; - if (composite.match(/###a(.*?)href="(.*?)"(.*?)###(.*?)/i)) { - anchors[j] = ''; - anchors[j - 1] = composite.replace(/###a(.*?)href="(.*?)"(.*?)###(.*?)/i, '$4'); - - tmp[i] = ''; - tmp[i + 1] = anchors.reverse().join(''); - - break; - } - } - } - - html = tmp.reverse().join(''); - } - return mpReconvertTags.call(this, html, data); }).bind(this); diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js deleted file mode 100644 index 8d61cbab40..0000000000 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js +++ /dev/null @@ -1,28 +0,0 @@ -$.Redactor.prototype.WoltLabList = function() { - "use strict"; - - return { - init: function () { - this.list.combineAfterAndBefore = (function (block) { - var $prev = $(block).prev(); - var $next = $(block).next(); - var isEmptyBlock = (block && block.tagName === 'P' && (block.innerHTML === '
' || block.innerHTML === '')); - - // WoltLab fix: closest() was missing the 2nd parameter causing - // it to match on lists being Redactor's ancestor - var isBlockWrapped = ($prev.closest('ol, ul', this.core.editor()[0]).length === 1 && $next.closest('ol, ul', this.core.editor()[0]).length === 1); - - if (isEmptyBlock && isBlockWrapped) - { - $prev.children('li').last().append(this.marker.get()); - $prev.append($next.contents()); - this.selection.restore(); - - return true; - } - - return false; - }).bind(this); - } - }; -}; -- 2.20.1