From e100aebaf2a04af7ba309d99dccdb62f2df785ff Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 24 Feb 2015 09:38:24 +0100 Subject: [PATCH] Fixed code bbcode --- .../js/3rdParty/redactor/plugins/wbbcode.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index eb1a6c905d..43f0f8b9e2 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -121,6 +121,7 @@ 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(); @@ -2007,6 +2008,7 @@ 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(); @@ -2090,6 +2092,35 @@ 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. */ -- 2.20.1