From bbd3aa2ec8452e7812b02a40146dc29e6ae34e0a Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Tue, 13 Feb 2018 12:05:20 +0100 Subject: [PATCH] Custom format remover plugin for CKEditor. --- CHANGELOG | 1 + .../static/js/core/remove-format-plugin.js | 50 +++++++++++++++++++ openslides/core/static/js/core/site.js | 1 + 3 files changed, 52 insertions(+) create mode 100644 openslides/core/static/js/core/remove-format-plugin.js diff --git a/CHANGELOG b/CHANGELOG index e1af94868..631e21553 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -117,6 +117,7 @@ Core: - Preparations for the SAML plugin; Fixed caching of main views [#3535]. - Removed unnecessary OPTIONS request in config [#3541]. - Added possibility to upload custom fonts for projector and pdf [#3568]. +- Use custom format cleanup plugin for CKEditor [#3576]. Mediafiles: - Fixed reloading of PDF on page change [#3274]. diff --git a/openslides/core/static/js/core/remove-format-plugin.js b/openslides/core/static/js/core/remove-format-plugin.js new file mode 100644 index 000000000..046dce06c --- /dev/null +++ b/openslides/core/static/js/core/remove-format-plugin.js @@ -0,0 +1,50 @@ +(function () { + +'use strict'; + +angular.module('OpenSlidesApp.core.remove-format-plugin', [ + 'OpenSlidesApp.core', +]) + +/* + * Plugin for the CKEditor that hooks into the removeformat plugin + * which is a default plugin enabled by 'cleanup' in the config + * toolbar. + * We change the behavior of the removeformat command here: + * It should not remove any tags and styles, but only the + * 'DISALLOWED_STYLES'. Removeformat traverses through the DOM + * and calles for every element the custom filter down below. + * We change the element and return false, so the removeformat + * plugin does not clean it up. + */ +.factory('OSRemoveFormatPlugin', [ + 'Editor', + 'gettextCatalog', + function (Editor, gettextCatalog) { + var DISALLOWED_STYLES = ['color', 'background-color']; + return { + getPlugin: function () { + return { + init: function (editor) { + editor.addRemoveFormatFilter(function (element) { + _.forEach(DISALLOWED_STYLES, function (style) { + element.removeStyle(style); + }); + return false; + }); + }, + }; + }, + }; + } +]) + +.run([ + 'Editor', + 'OSRemoveFormatPlugin', + function (Editor, OSRemoveFormatPlugin, gettext) { + Editor.registerPlugin('OSRemoveFormat', OSRemoveFormatPlugin.getPlugin()); + } +]); + +}()); diff --git a/openslides/core/static/js/core/site.js b/openslides/core/static/js/core/site.js index b7a7c5571..931f8bb14 100644 --- a/openslides/core/static/js/core/site.js +++ b/openslides/core/static/js/core/site.js @@ -7,6 +7,7 @@ angular.module('OpenSlidesApp.core.site', [ 'OpenSlidesApp.core', 'OpenSlidesApp.core.start', 'OpenSlidesApp.core.csv', + 'OpenSlidesApp.core.remove-format-plugin', 'OpenSlidesApp.poll.majority', 'ui.router', 'colorpicker.module',