From: Alexander Ebert Date: Sun, 28 Aug 2016 14:24:45 +0000 (+0200) Subject: Fixed list elements being matched outside of Redactor X-Git-Tag: 3.0.0_Beta_1~437 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2ccc7e0e133d288886e19d59e5e6331f17d54ebf;p=GitHub%2FWoltLab%2FWCF.git Fixed list elements being matched outside of Redactor --- diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index e34f361476..e8a72536f7 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -24,6 +24,7 @@ '{@$__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}', @@ -197,6 +198,7 @@ 'WoltLabInlineCode', 'WoltLabInsert', 'WoltLabLink', + 'WoltLabList', 'WoltLabModal', 'WoltLabPaste', 'WoltLabQuote', diff --git a/wcfsetup/install/files/acp/templates/wysiwyg.tpl b/wcfsetup/install/files/acp/templates/wysiwyg.tpl index 7ac629d3fe..e8a72536f7 100644 --- a/wcfsetup/install/files/acp/templates/wysiwyg.tpl +++ b/wcfsetup/install/files/acp/templates/wysiwyg.tpl @@ -24,6 +24,7 @@ '{@$__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}', @@ -100,6 +101,29 @@ element.value = autosave.getInitialValue(); } + var placeholderCallback = null, replyContainer = element.closest('.messageQuickReplyContent'); + if (replyContainer) { + var container = elById('messageQuickReply'); + if (container.classList.contains('messageQuickReplyCollapsed')) { + placeholderCallback = function (event) { + if (event instanceof Event) { + event.preventDefault(); + } + + if (container.classList.contains('messageQuickReplyCollapsed')) { + container.classList.remove('messageQuickReplyCollapsed'); + $(element).redactor('focus.end'); + + replyContainer.removeEventListener(WCF_CLICK_EVENT, placeholderCallback); + } + + return null; + }; + + replyContainer.addEventListener(WCF_CLICK_EVENT, placeholderCallback); + } + } + var config = { buttons: buttons, formatting: ['p', 'h2', 'h3', 'h4'], @@ -149,7 +173,7 @@ linkify: false, linkSize: 0xBADC0DED, // some random value to disable truncating minHeight: 200, - placeholder: elData(element, 'placeholder') || '', + //placeholder: elData(element, 'placeholder') || '', plugins: [ // Imperavi 'alignment', @@ -174,6 +198,7 @@ 'WoltLabInlineCode', 'WoltLabInsert', 'WoltLabLink', + 'WoltLabList', 'WoltLabModal', 'WoltLabPaste', 'WoltLabQuote', @@ -189,7 +214,8 @@ buttons: buttonOptions, buttonMobile: buttonMobile, customButtons: customButtons, - highlighters: highlighters + highlighters: highlighters, + placeholderCallback: placeholderCallback } }; @@ -217,10 +243,15 @@ config.callbacks = config.callbacks || { }; config.callbacks.init = function() { + var editor = element.previousElementSibling; + if (replyContainer) { + elData(editor, 'reply-placeholder', elData(element, 'reply-placeholder')); + } + // slight delay to allow Redactor to initialize itself window.setTimeout(function() { $(element).redactor('code.set', content); - $(element).redactor('core.editor')[0].classList.add('redactorReady'); + editor.classList.add('redactorReady'); }, 10); }; 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..4d0ef48911 --- /dev/null +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js @@ -0,0 +1,28 @@ +$.Redactor.prototype.WoltLabCaret = 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); + } + }; +};