Fixed handling of code bbcodes
authorAlexander Ebert <ebert@woltlab.com>
Tue, 24 Feb 2015 11:19:54 +0000 (12:19 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 24 Feb 2015 11:19:54 +0000 (12:19 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js

index 37c3ce522e220603b93d87146ca320bb14a7f724..32fa25eea1928f757b2f6f1e6277bc3f56d96919 100644 (file)
@@ -121,7 +121,6 @@ RedactorPlugins.wbbcode = function() {
                                        this.$textarea.val(this.wbbcode.convertToHtml(this.$textarea.val()));
                                        this.code.offset = this.$textarea.val().length;
                                        this.code.showVisual();
-                                       this.wbbcode.fixCodeBBCode();
                                        this.wbbcode.fixBlockLevelElements();
                                        this.wutil.selectionEndOfEditor();
                                        this.wbbcode.observeQuotes();
@@ -1215,6 +1214,10 @@ RedactorPlugins.wbbcode = function() {
                                }
                        }
                        
+                       // remove <p> wrapping a quote or a div
+                       data = data.replace(/<(?:div|p)><(blockquote|div)/g, '<$1');
+                       data = data.replace(/<\/(blockquote|div)><\/(?:div|p)>/g, '</$1>');
+                       
                        // insert codes
                        if ($cachedCodes.length) {
                                for (var $i = $cachedCodes.length - 1; $i >= 0; $i--) {
@@ -1304,10 +1307,6 @@ RedactorPlugins.wbbcode = function() {
                                }
                        }
                        
-                       // remove <p> wrapping a quote or a div
-                       data = data.replace(/<(?:div|p)><(blockquote|div)/g, '<$1');
-                       data = data.replace(/<\/(blockquote|div)><\/(?:div|p)>/g, '</$1>');
-                       
                        WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'afterConvertToHtml', { data: data });
                        
                        return data;
@@ -2008,7 +2007,6 @@ RedactorPlugins.wbbcode = function() {
                                        // set caret after code listing
                                        var $codeBox = this.$editor.find('.codeBox:not(.jsRedactorCodeBox)');
                                        
-                                       this.wbbcode.fixCodeBBCode($codeBox[0]);
                                        this.wbbcode.observeCodeListings();
                                        this.wbbcode.fixBlockLevelElements();
                                        
@@ -2092,35 +2090,6 @@ RedactorPlugins.wbbcode = function() {
                        }
                },
                
-               /**
-                * Fixes the code bbcode.
-                * 
-                * @param       Element         codeBox
-                * @returns
-                */
-               fixCodeBBCode: function(codeBox) {
-                       if (!codeBox) {
-                               var $codeBoxes = this.$editor[0].querySelectorAll('div.codeBox');
-                               for (var $i = 0, $length = $codeBoxes.length; $i < $length; $i++) {
-                                       this.wbbcode.fixCodeBBCode($codeBoxes[$i]);
-                               }
-                               
-                               return;
-                       }
-                       
-                       codeBox = codeBox[0] || codeBox;
-                       
-                       // sometimes the inner div is missing
-                       if (codeBox.children.length > 1) {
-                               var $container = document.createElement('div');
-                               codeBox.insertBefore($container, codeBox.firstChild);
-                               
-                               while ($container.nextElementSibling) {
-                                       $container.appendChild($container.nextElementSibling);
-                               }
-                       }
-               },
-               
                /**
                 * Ensures that there is a paragraph in front of each block-level element because you cannot click in between two of them.
                 */