Removing spans again
authorAlexander Ebert <ebert@woltlab.com>
Tue, 30 Aug 2016 09:43:19 +0000 (11:43 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 30 Aug 2016 10:28:30 +0000 (12:28 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index 383a37790829a65fffd7551915a19b00bbb42d2c..02c15009cfca6b3388d8c51001c07f65a7ffce52 100644 (file)
@@ -3,6 +3,10 @@ $.Redactor.prototype.WoltLabClean = function() {
        
        return {
                init: function () {
+                       this.opts.pasteInlineTags = this.opts.pasteInlineTags.filter(function (value) {
+                               return (value !== 'span');
+                       });
+                       
                        var mpOnSet = this.clean.onSet;
                        this.clean.onSet = (function (html) {
                                return mpOnSet.call(this, html.replace(/\u200B/g, ''));
@@ -10,9 +14,10 @@ $.Redactor.prototype.WoltLabClean = function() {
                        
                        var mpOnSync = this.clean.onSync;
                        this.clean.onSync = (function (html) {
-                               var div, replacements = {};
+                               var div = elCreate('div');
+                               var replacements = {};
+                               
                                if (html.indexOf('<pre') !== -1) {
-                                       div = elCreate('div');
                                        div.innerHTML = html;
                                        
                                        elBySelAll('pre', div, function (pre) {
@@ -27,15 +32,18 @@ $.Redactor.prototype.WoltLabClean = function() {
                                
                                html = mpOnSync.call(this, html);
                                
-                               if (div) {
-                                       div.innerHTML = html;
-                                       
-                                       elBySelAll('pre', div, function (pre) {
+                               div.innerHTML = html;
+                               
+                               elBySelAll('span', div, function (span) {
+                                       span.outerHTML = span.innerHTML;
+                               });
+                               elBySelAll('pre', div, function (pre) {
+                                       if (replacements.hasOwnProperty(pre.textContent)) {
                                                pre.textContent = replacements[pre.textContent];
-                                       });
-                                       
-                                       html = div.innerHTML;
-                               }
+                                       }
+                               });
+                               
+                               html = div.innerHTML;
                                
                                return html;
                        }).bind(this);
@@ -54,6 +62,15 @@ $.Redactor.prototype.WoltLabClean = function() {
                                
                                return html;
                        }).bind(this);
+                       
+                       var mpStripTags = this.clean.stripTags;
+                       this.clean.stripTags = (function(input, denied) {
+                               if (Array.isArray(denied)) {
+                                       denied.push('span');
+                               }
+                               
+                               return mpStripTags.call(this, input, denied);
+                       }).bind(this);
                }
        }
 };