From 86797f3582bd942f0cf845c2927a044e96bcd3d5 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 10 Jan 2015 03:22:29 +0100 Subject: [PATCH] Work-around for text alignment affecting non-editable elements --- .../js/3rdParty/redactor/plugins/wbbcode.js | 35 ++++++++++++++++++- .../3rdParty/redactor/plugins/wmonkeypatch.js | 20 +++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index bf31009969..80931250e6 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -4,7 +4,7 @@ if (!RedactorPlugins) var RedactorPlugins = {}; * Provides the smiley button and modifies the source mode to transform HTML into BBCodes. * * @author Alexander Ebert, Marcel Werk - * @copyright 2001-2014 WoltLab GmbH + * @copyright 2001-2015 WoltLab GmbH * @license GNU Lesser General Public License */ RedactorPlugins.wbbcode = function() { @@ -149,6 +149,8 @@ RedactorPlugins.wbbcode = function() { this.wbbcode.observeCodeListings(); this.wbbcode.observeQuotes(); }).bind(this)); + + WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'fixFormatting_' + $identifier, $.proxy(this.wbbcode.fixFormatting, this)); }, /** @@ -1948,6 +1950,37 @@ RedactorPlugins.wbbcode = function() { $addSpacing(blockElement, 'previousElementSibling'); $addSpacing(blockElement, 'nextElementSibling'); }).bind(this)); + }, + + /** + * Fixes incorrect formatting applied to element that should be left untouched. + * + * @param object data + */ + fixFormatting: function(data) { + var $stripTextAlign = function(element) { + element.style.removeProperty('text-align'); + + for (var $i = 0; $i < element.children.length; $i++) { + $stripTextAlign(element.children[$i]); + } + }; + + for (var $i = 0; $i < this.alignment.blocks.length; $i++) { + var $block = this.alignment.blocks[$i]; + switch ($block.tagName) { + case 'BLOCKQUOTE': + $block.style.removeProperty('text-align'); + $stripTextAlign($block.children[0]); + break; + + case 'DIV': + if ($block.classList.contains('codeBox')) { + $stripTextAlign($block); + } + break; + } + } } }; }; diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js index d3aff35eb9..8aa23a4ed0 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js @@ -6,12 +6,12 @@ if (!RedactorPlugins) var RedactorPlugins = {}; * way or a work-around would cause a giant pile of boilerplates. * * ATTENTION! - * This plugin partially contains code taken from Redactor, Copyright (c) 2009-2014 Imperavi LLC. + * This plugin partially contains code taken from Redactor, Copyright (c) 2009-2015 Imperavi LLC. * Under no circumstances you are allowed to use potions or entire code blocks for use anywhere * except when directly working with WoltLab Community Framework. * * @author Alexander Ebert - * @copyright 2001-2014 WoltLab GmbH, 2009-2014 Imperavi LLC. + * @copyright 2001-2015 WoltLab GmbH, 2009-2015 Imperavi LLC. * @license http://imperavi.com/redactor/license/ */ RedactorPlugins.wmonkeypatch = function() { @@ -23,6 +23,7 @@ RedactorPlugins.wmonkeypatch = function() { */ init: function() { // module overrides + this.wmonkeypatch.alignment(); this.wmonkeypatch.button(); this.wmonkeypatch.caret(); this.wmonkeypatch.clean(); @@ -103,6 +104,21 @@ RedactorPlugins.wmonkeypatch = function() { }).bind(this)); }, + /** + * Partially overwrites the 'alignment' module. + * + * - Firing an event after setBlocks() has been called, useful to strip unwanted formatting + */ + alignment: function() { + // alignment.setBlocks + var $mpSetBlocks = this.alignment.setBlocks; + this.alignment.setBlocks = (function(type) { + $mpSetBlocks.call(this, type); + + WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'fixFormatting_' + this.$textarea.wcfIdentify()); + }).bind(this); + }, + /** * Partially overwrites the 'button' module. * -- 2.20.1