From: Alexander Ebert Date: Fri, 1 Sep 2017 14:43:32 +0000 (+0200) Subject: Preserve text formatting when creating lists X-Git-Tag: 3.1.0_Alpha_3~4^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c7f3155dc965adfad6657b6b32ac0e7aad716722;p=GitHub%2FWoltLab%2FWCF.git Preserve text formatting when creating lists --- diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index 9182298968..4df2ba9e35 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -29,6 +29,7 @@ '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLine.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}', @@ -205,6 +206,7 @@ 'WoltLabInsert', 'WoltLabLine', {if $__wcf->getBBCodeHandler()->isAvailableBBCode('url')}'WoltLabLink',{/if} + 'WoltLabList', 'WoltLabModal', 'WoltLabObserve', 'WoltLabPaste', diff --git a/wcfsetup/install/files/acp/templates/wysiwyg.tpl b/wcfsetup/install/files/acp/templates/wysiwyg.tpl index 9182298968..4df2ba9e35 100644 --- a/wcfsetup/install/files/acp/templates/wysiwyg.tpl +++ b/wcfsetup/install/files/acp/templates/wysiwyg.tpl @@ -29,6 +29,7 @@ '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}', '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLine.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}', @@ -205,6 +206,7 @@ 'WoltLabInsert', 'WoltLabLine', {if $__wcf->getBBCodeHandler()->isAvailableBBCode('url')}'WoltLabLink',{/if} + 'WoltLabList', 'WoltLabModal', 'WoltLabObserve', 'WoltLabPaste', diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js new file mode 100644 index 0000000000..3c144576ef --- /dev/null +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js @@ -0,0 +1,93 @@ +$.Redactor.prototype.WoltLabList = function() { + "use strict"; + + return { + init: function () { + this.list.toggle = (function(cmd) { + if (this.utils.inBlocks(['table', 'td', 'th', 'tr'])) { + return; + } + + var tag = (cmd === 'orderedlist' || cmd === 'ol') ? 'OL' : 'UL'; + cmd = (tag === 'OL') ? 'orderedlist' : 'unorderedlist'; + + var $list = $(this.selection.current()).parentsUntil('.redactor-in', 'ul, ol').first(); + + this.placeholder.hide(); + this.buffer.set(); + + if ($list.length !== 0 && $list[0].tagName === tag && this.utils.isRedactorParent($list)) { + this.selection.save(); + + // remove list + $list.find('ul, ol').each(function () { + var parent = $(this).closest('li'); + $(this).find('li').each(function () { + $(parent).after(this); + }); + }); + + $list.find('ul, ol').remove(); + $list.find('li').each(function () { + return $(this).replaceWith(function () { + return $('

').append($(this).contents()); + }); + }); + + $list.replaceWith(function () { + return $(this).contents(); + }); + + this.selection.restore(); + return; + } + + + this.selection.save(); + + if ($list.length !== 0 && $list[0].tagName !== tag) { + $list.each($.proxy(function (i, s) { + this.utils.replaceToTag(s, tag); + + }, this)); + } + else { + document.execCommand('insert' + cmd); + } + + this.selection.restore(); + + var $insertedList = this.list.get(); + if (!$insertedList) { + if (!this.selection.block()) { + document.execCommand('formatblock', false, 'p'); + } + + return; + } + + // clear span + // WoltLab modification: do not remove + /*$insertedList.find('span').replaceWith(function () { + return $(this).contents(); + });*/ + + // remove style + $insertedList.find(this.opts.inlineTags.join(',')).each(function () { + // WoltLab modification: exclude spans + if (this.nodeName !== 'SPAN') $(this).removeAttr('style'); + }); + + // remove block-element list wrapper + var $listParent = $insertedList.parent(); + if (this.utils.isRedactorParent($listParent) && $listParent[0].tagName !== 'LI' && this.utils.isBlock($listParent)) { + this.selection.save(); + + $listParent.replaceWith($listParent.contents()); + + this.selection.restore(); + } + }).bind(this); + } + }; +};