From: Alexander Ebert Date: Tue, 26 Aug 2014 14:33:13 +0000 (+0200) Subject: Fixed inserting of quotes on init and w/ line breaks X-Git-Tag: 2.1.0_Alpha_1~408 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7e7bc9b3796a6925386b0d636bb139a0119d32fd;p=GitHub%2FWoltLab%2FWCF.git Fixed inserting of quotes on init and w/ line breaks --- diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 0c3d2619e2..43e9c4272a 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -843,9 +843,7 @@ RedactorPlugins.wbbcode = { var $parent = this.getParent(); $parent = ($parent) ? $($parent) : $parent; var $quote = ($parent) ? $parent.closest('blockquote.quoteBox', this.$editor.get()[0]) : { length: 0 }; - console.clear(); - console.debug($current); - console.debug($parent); + switch (data.event.which) { // arrow down case $.ui.keyCode.DOWN: @@ -854,31 +852,21 @@ RedactorPlugins.wbbcode = { var $container = $current.closest('div', $quote[0]); if (!$container.next().length) { this.insertingAfterLastElement($quote); - console.debug("case#0"); data.cancel = true; } - else { - console.debug("case#1"); - } } else if ($parent.next('blockquote.quoteBox').length) { this.selectionStart($parent.next().find('> div > div:first')); - console.debug("case#2"); + data.cancel = true; } - else { - console.debug("case#3"); - } } else if ($current.next('blockquote.quoteBox').length) { this.selectionStart($current.next().find('> div > div:first')); - console.debug("case#4"); + data.cancel = true; } - else { - console.debug("case#5"); - } break; // arrow up @@ -894,7 +882,6 @@ RedactorPlugins.wbbcode = { var $previousElement = $quote.prev(); if ($previousElement.length === 0) { - console.debug("case#1"); var $node = $(this.opts.emptyHtml); $node.insertBefore($quote); this.selectionStart($node); @@ -1012,8 +999,10 @@ RedactorPlugins.wbbcode = { * * @param string author * @param string link + * @param string html + * @param string plainText */ - insertQuoteBBCode: function(author, link) { + insertQuoteBBCode: function(author, link, html, plainText) { if (this.inWysiwygMode()) { var $html = '
' + '
' @@ -1029,23 +1018,26 @@ RedactorPlugins.wbbcode = { this.insertHtml($html); var $quote = $('#redactorInsertedQuote'); - var $container = $('
' + this.opts.invisibleSpace + '
').insertAfter($quote.find('> div > header')); + var $container = $('
' + (html ? html : this.opts.invisibleSpace) + '
').insertAfter($quote.find('> div > header')); $quote.removeAttr('id'); this.selectionStart($container[0]); this._observeQuotes(); } else { - var $bbcode = '[quote][/quote]'; + var $bbcode = '[quote]'; if (author) { if (link) { - $bbcode = "[quote='" + author + "','" + link + "'][/quote]"; + $bbcode = "[quote='" + author + "','" + link + "']"; } else { - $bbcode = "[quote='" + author + "'][/quote]"; + $bbcode = "[quote='" + author + "']"; } } + if (plainText) $bbcode += plainText; + $bbcode += '[/quote]'; + this.insertAtCaret($bbcode); } }, diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index d1b2d3215c..a4a84b98bb 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -325,5 +325,12 @@ RedactorPlugins.wutil = { */ getName: function() { return this.$source.wcfIdentify(); + }, + + /** + * Sets the selection after the last direct children of the editor. + */ + selectionEndOfEditor: function() { + this.selectionEnd(this.$editor.children(':last')[0]); } }; diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index 352c066f04..cf930528bd 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -891,7 +891,11 @@ WCF.Message.QuickReply = Class.extend({ } if ($.browser.redactor) { - this._messageField.redactor('insertDynamic', data.returnValues.template); + var $html = WCF.String.unescapeHTML(data.returnValues.template); + $html = this._messageField.redactor('transformQuote', $html); + + this._messageField.redactor('selectionEndOfEditor'); + this._messageField.redactor('insertDynamic', $html, data.returnValues.template); } else { this._messageField.val(data.returnValues.template); @@ -2706,19 +2710,19 @@ WCF.Message.Quote.Manager = Class.extend({ var $quote = $.trim($listItem.children('div.jsFullQuote').text()); var $message = $listItem.parents('article.message'); - // build quote tag - $quote = "[quote='" + $message.attr('data-username') + "','" + $message.data('link') + "']" + $quote + "[/quote]"; - // insert into editor if ($.browser.redactor) { if (this._editorElementAlternative === null) { - this._editorElement.redactor('insertDynamic', $quote); + this._editorElement.redactor('insertQuoteBBCode', $message.attr('data-username'), $message.data('link'), $quote, $quote);// $quote); } else { - this._editorElementAlternative.redactor('insertDynamic', $quote); + this._editorElementAlternative.redactor('insertQuoteBBCode', $message.attr('data-username'), $message.data('link'), $quote, $quote);// $quote); } } else { + // build quote tag + $quote = "[quote='" + $message.attr('data-username') + "','" + $message.data('link') + "']" + $quote + "[/quote]"; + // plain textarea var $textarea = (this._editorElementAlternative === null) ? this._editorElement : this._editorElementAlternative; var $value = $textarea.val();