Fixed inserting of quotes on init and w/ line breaks
authorAlexander Ebert <ebert@woltlab.com>
Tue, 26 Aug 2014 14:33:13 +0000 (16:33 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 26 Aug 2014 14:33:13 +0000 (16:33 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js
wcfsetup/install/files/js/WCF.Message.js

index 0c3d2619e2e3e453b65624a780d74349e0d500e9..43e9c4272a0220421e8a5485bdba407dbd22fc76 100644 (file)
@@ -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 = '<blockquote class="quoteBox" cite="' + link + '" data-author="' + author + '" id="redactorInsertedQuote">'
                                        + '<div class="container containerPadding">'
@@ -1029,23 +1018,26 @@ RedactorPlugins.wbbcode = {
                        this.insertHtml($html);
                        
                        var $quote = $('#redactorInsertedQuote');
-                       var $container = $('<div>' + this.opts.invisibleSpace + '</div>').insertAfter($quote.find('> div > header'));
+                       var $container = $('<div>' + (html ? html : this.opts.invisibleSpace) + '</div>').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);
                }
        },
index d1b2d3215c11f66d99b8faa657f0a63d4de7293b..a4a84b98bb232a675d39efa2b6b846466244d679 100644 (file)
@@ -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]);
        }
 };
index 352c066f047515627bb5eeb7e09cb5ab234caf21..cf930528bd7a6e7915d17f21d8a53ca4d8d691f8 100644 (file)
@@ -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();