Strip font color/family/size when clean paste is enabled
authorAlexander Ebert <ebert@woltlab.com>
Wed, 25 Sep 2019 08:37:31 +0000 (10:37 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 25 Sep 2019 08:37:31 +0000 (10:37 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index 062f165b2b19571e48a05ba5ca3861566959180c..26237a4206f379675da618462f3ba34309f8c0d6 100644 (file)
@@ -239,7 +239,7 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        });
                                }
                                
-                               elBySelAll('span', div, function (span) {
+                               elBySelAll('span', div, (function (span) {
                                        if (span.classList.contains('redactor-selection-marker')) return;
                                        
                                        if (span.hasAttribute('style') && span.style.length) {
@@ -250,6 +250,14 @@ $.Redactor.prototype.WoltLabClean = function() {
                                                
                                                var activeStyles = (color ? 1 : 0) + (fontFamily ? 1 : 0) + (fontSize ? 1 : 0);
                                                while (activeStyles > 1) {
+                                                       if (this.opts.pastePlainText) {
+                                                               span.style.removeProperty('color');
+                                                               span.style.removeProperty('font-family');
+                                                               span.style.removeProperty('font-size');
+                                                               
+                                                               return;
+                                                       }
+                                                       
                                                        var newSpan = elCreate('span');
                                                        if (color) {
                                                                newSpan.style.setProperty('color', color, '');
@@ -281,7 +289,7 @@ $.Redactor.prototype.WoltLabClean = function() {
                                                
                                                elRemove(span);
                                        }
-                               });
+                               }).bind(this));
                                
                                elBySelAll('p', div, function (p) {
                                        if (p.classList.contains('MsoNormal')) {
@@ -644,6 +652,11 @@ $.Redactor.prototype.WoltLabClean = function() {
                                });
                        });
                        
+                       if (this.opts.pastePlainText) {
+                               // Ignore any style attributes, they are removed anyway.
+                               return;
+                       }
+                       
                        // Search for span[style] that contain styles that actually do nothing, because their set style
                        // equals the inherited style from its ancestors.
                        elBySelAll('span[style]', this.$editor[0], function(element) {