Fixed some more glitches
authorAlexander Ebert <ebert@woltlab.com>
Mon, 19 Dec 2016 16:29:54 +0000 (17:29 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 19 Dec 2016 16:35:20 +0000 (17:35 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index abbb5bae0c474cdffcc370f404ffdae764147613..060c3b76162c848727123b065f03b6899936172e 100644 (file)
@@ -160,6 +160,13 @@ $.Redactor.prototype.WoltLabClean = function() {
                                
                                elBySelAll('img', div, function (img) {
                                        img.removeAttribute('style');
+                                       
+                                       if (img.hasAttribute('alt')) {
+                                               // The editor trips over `<`, causing the DOM to be seriously
+                                               // messed up. Until this is resolved, we're simply dropping it,
+                                               // at least for smilies it is later restored.
+                                               img.setAttribute('alt', img.getAttribute('alt').replace(/</g, ''));
+                                       }
                                });
                                
                                elBySelAll('br', div, function (br) {
@@ -202,6 +209,28 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        elRemove(marker);
                                });
                                
+                               elBySelAll('p', div, function (p) {
+                                       // remove garbage paragraphs that contain absolutely nothing
+                                       var remove = false;
+                                       if (p.childNodes.length === 0) {
+                                               remove = true;
+                                       }
+                                       else if (p.textContent === '') {
+                                               remove = true;
+                                               
+                                               // check if there are only <span> elements
+                                               elBySelAll('*', p, function (element) {
+                                                       if (element.nodeName !== 'SPAN') {
+                                                               remove = false;
+                                                       }
+                                               });
+                                       }
+                                       
+                                       if (remove) {
+                                               elRemove(p);
+                                       }
+                               });
+                               
                                return div.innerHTML;
                        }).bind(this);