Improved inserting quote preserving selection
authorAlexander Ebert <ebert@woltlab.com>
Fri, 21 Nov 2014 11:14:58 +0000 (12:14 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 21 Nov 2014 11:14:58 +0000 (12:14 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 7019563ffaa100dddbed5c765560da2ec0151754..e647f2bbe0ae9112868c5e2a0a564f899886fb96 100644 (file)
@@ -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(/^<p>/, '').replace(/<\/p>$/, ''));
index 98cb37b05886ca0904d61aa14e1888861db9f775..d3fab51bce45be731d1be271c33e3afb4a9ab204 100644 (file)
@@ -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);