Fixed list elements being matched outside of Redactor
authorAlexander Ebert <ebert@woltlab.com>
Sun, 28 Aug 2016 14:24:45 +0000 (16:24 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 28 Aug 2016 14:24:50 +0000 (16:24 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/acp/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js [new file with mode: 0644]

index e34f361476a0a1fee8226dff0f9c8b8d0128bafb..e8a72536f7a0ccad5e3a102b355e636acadfb250 100644 (file)
@@ -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}',
                                        'WoltLabInlineCode',
                                        'WoltLabInsert',
                                        'WoltLabLink',
+                                       'WoltLabList',
                                        'WoltLabModal',
                                        'WoltLabPaste',
                                        'WoltLabQuote',
index 7ac629d3fed69f655626bec1211f242db0435055..e8a72536f7a0ccad5e3a102b355e636acadfb250 100644 (file)
@@ -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}',
                                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'],
                                linkify: false,
                                linkSize: 0xBADC0DED, // some random value to disable truncating
                                minHeight: 200,
-                               placeholder: elData(element, 'placeholder') || '',
+                               //placeholder: elData(element, 'placeholder') || '',
                                plugins: [
                                        // Imperavi
                                        'alignment',
                                        'WoltLabInlineCode',
                                        'WoltLabInsert',
                                        'WoltLabLink',
+                                       'WoltLabList',
                                        'WoltLabModal',
                                        'WoltLabPaste',
                                        'WoltLabQuote',
                                        buttons: buttonOptions,
                                        buttonMobile: buttonMobile,
                                        customButtons: customButtons,
-                                       highlighters: highlighters
+                                       highlighters: highlighters,
+                                       placeholderCallback: placeholderCallback
                                }
                        };
                        
                        
                        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 (file)
index 0000000..4d0ef48
--- /dev/null
@@ -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 === '<br>' || 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);
+               }
+       };
+};