Improved pasting
authorAlexander Ebert <ebert@woltlab.com>
Thu, 20 Oct 2016 11:11:44 +0000 (13:11 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 20 Oct 2016 11:11:44 +0000 (13:11 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index 38346dcc002725aca85989d1984499f67f7f3794..6d30544dad8b9f9e2440d34fee1604b7a8325bb8 100644 (file)
@@ -133,7 +133,41 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        }
                                });
                                
-                               return mpOnPaste.call(this, div.innerHTML, data, insert);
+                               elBySelAll('br', div, function (br) {
+                                       br.parentNode.insertBefore(document.createTextNode('@@@WOLTLAB-BR-MARKER@@@'), br);
+                               });
+                               
+                               html = mpOnPaste.call(this, div.innerHTML, data, insert);
+                               
+                               html = html.replace(/@@@WOLTLAB-BR-MARKER@@@/g, '<woltlab-br-marker></woltlab-br-marker>');
+                               
+                               div.innerHTML = html;
+                               
+                               elBySelAll('woltlab-br-marker', div, function (marker) {
+                                       var parent = marker.parentNode;
+                                       
+                                       if (parent.nodeName === 'P') {
+                                               var p = elCreate('p');
+                                               while (marker.nextSibling) {
+                                                       p.appendChild(marker.nextSibling);
+                                               }
+                                               p.appendChild(elCreate('br'));
+                                               
+                                               parent.parentNode.insertBefore(p, parent.nextSibling);
+                                               
+                                               var previous = marker.previousElementSibling;
+                                               if (previous && previous.nodeName === 'BR') {
+                                                       elRemove(previous);
+                                               }
+                                       }
+                                       else {
+                                               parent.insertBefore(elCreate('br'), marker);
+                                       }
+                                       
+                                       elRemove(marker);
+                               });
+                               
+                               return div.innerHTML;
                        }).bind(this);
                        
                        var storage = [];