From 65fa77014607cef4622e2f56949798d67f65efdc Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 21 Nov 2014 12:14:58 +0100 Subject: [PATCH] Improved inserting quote preserving selection --- .../js/3rdParty/redactor/plugins/wbbcode.js | 16 +++++++++++++--- .../js/3rdParty/redactor/plugins/wmonkeypatch.js | 8 ++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 7019563ffa..e647f2bbe0 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -1348,14 +1348,24 @@ RedactorPlugins.wbbcode = function() { var $button = this.modal.createActionButton(this.lang.get('save')); if (insertQuote) { + this.selection.save(); + $button.click($.proxy(function() { var $author = $('#redactorQuoteAuthor').val(); var $link = WCF.String.escapeHTML($('#redactorQuoteLink').val()); - var $quote = this.wbbcode.insertQuoteBBCode($author, $link); + this.selection.restore(); + var $html = this.selection.getHtml(); + if (this.utils.isEmpty($html)) { + $html = ''; + } + + var $quote = this.wbbcode.insertQuoteBBCode($author, $link, $html); if ($quote !== null) { // set caret inside the quote - this.caret.setStart($quote.find('> div > div')[0]); + if (!$html.length) { + this.caret.setStart($quote.find('> div > div')[0]); + } } this.modal.close(); @@ -1419,7 +1429,7 @@ RedactorPlugins.wbbcode = function() { var $quote = null; if (this.wutil.inWysiwygMode()) { - var $innerHTML = (plainText) ? this.wbbcode.convertToHtml(plainText) : ''; + var $innerHTML = (plainText) ? this.wbbcode.convertToHtml(plainText) : html; var $id = WCF.getUUID(); var $html = this.wbbcode.convertToHtml($openTag + $id + $closingTag); $html = $html.replace($id, $innerHTML.replace(/^

/, '').replace(/<\/p>$/, '')); diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index 98cb37b058..d3fab51bce 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -531,8 +531,12 @@ RedactorPlugins.wmonkeypatch = function() { return; } - this.modal.dialog.wcfDialog('close'); - this.modal.dialog.remove(); + try { + this.modal.dialog.wcfDialog('close'); + this.modal.dialog.remove(); + } + catch (e) { } + this.modal.dialog = null; }).bind(this); -- 2.20.1