Improved quote handling
authorAlexander Ebert <ebert@woltlab.com>
Mon, 5 Sep 2016 14:57:40 +0000 (16:57 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 5 Sep 2016 15:54:51 +0000 (17:54 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabCaret.js
wcfsetup/install/files/js/WCF.Message.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js

index 7077de0e0a5f0df92964ee532b86911aa2030495..9e4c53e2a801d48cb94c275401717646a2ae8795 100644 (file)
@@ -19,6 +19,17 @@ $.Redactor.prototype.WoltLabCaret = function() {
                        this.WoltLabCaret._initInternalRange();
                },
                
+               paragraphAfterBlock: function (block) {
+                       var sibling = block.nextElementSibling;
+                       if (sibling && sibling.nodeName !== 'P') {
+                               sibling = elCreate('p');
+                               sibling.textContent = '\u200B';
+                               block.parentNode.insertBefore(sibling, block.nextSibling);
+                       }
+                       
+                       this.caret.after(block);
+               },
+               
                endOfEditor: function () {
                        var editor = this.core.editor()[0];
                        
index f4bfa110ab9c9373514e6a86aefeced093fd96f8..9077830e3256a14b4d434da9579cd155325ff0de 100644 (file)
@@ -1707,7 +1707,7 @@ WCF.Message.Quote.Manager = Class.extend({
                                var button = UiPageAction.get(buttonName);
                                if (button === undefined) {
                                        button = elCreate('a');
-                                       button.addEventListener(WCF_CLICK_EVENT, this._click.bind(this));
+                                       button.addEventListener('mousedown', this._click.bind(this));
                                        
                                        UiPageAction.add(buttonName, button);
                                }
@@ -1728,6 +1728,11 @@ WCF.Message.Quote.Manager = Class.extend({
         * Handles clicks on 'Show quotes'.
         */
        _click: function() {
+               var editor = document.activeElement;
+               if (editor.classList.contains('redactor-editor')) {
+                       $(editor.nextElementSibling).redactor('selection.save');
+               }
+               
                if (this._hasTemplate) {
                        this._dialog.wcfDialog('open');
                }
index 9da1fd53fe07c82abd9a4135395f2fb47d0958c1..5010ef8ac5c6cb2fecf80d265e27423038a6b98d 100644 (file)
@@ -53,26 +53,23 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util'
                _insertQuote: function (data) {
                        EventHandler.fire('com.woltlab.wcf.redactor2', 'showEditor');
                        
+                       var editor = this._editor.core.editor()[0];
+                       this._editor.selection.restore();
+                       
                        this._editor.buffer.set();
                        
-                       // caret must be within a `<p>`, if it is not move it
-                       /** @type Node */
+                       // caret must be within a `<p>`, if it is not: move it
                        var block = this._editor.selection.block();
-                       var redactor = this._editor.core.editor()[0];
-                       while (block.parentNode && block.parentNode !== redactor) {
-                               block = block.parentNode;
-                       }
                        
-                       this._editor.caret.after(block);
                        
-                       var quoteId = Core.getUuid();
-                       this._editor.insert.html('<woltlab-quote id="' + quoteId + '"></woltlab-quote>');
+                       while (block && block.parentNode !== editor) {
+                               block = block.parentNode;
+                       }
                        
-                       var quote = elById(quoteId);
+                       var quote = elCreate('woltlab-quote');
                        elData(quote, 'author', data.author);
                        elData(quote, 'link', data.link);
                        
-                       this._editor.selection.restore();
                        var content = data.content;
                        if (data.isText) {
                                content = StringUtil.escapeHTML(content);
@@ -84,9 +81,13 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util'
                        // bypass the editor as `insert.html()` doesn't like us
                        quote.innerHTML = content;
                        
-                       quote.removeAttribute('id');
+                       block.parentNode.insertBefore(quote, block.nextSibling);
+                       
+                       if (block.nodeName === 'P' && (block.innerHTML === '<br>' || block.innerHTML.replace(/\u200B/g, '') === '')) {
+                               block.parentNode.removeChild(block);
+                       }
                        
-                       this._editor.caret.after(quote);
+                       this._editor.WoltLabCaret.paragraphAfterBlock(quote);
                        
                        this._editor.buffer.set();
                },