Fixed text alignment lost on new line
authorAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2016 11:03:49 +0000 (13:03 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 7 Sep 2016 11:03:49 +0000 (13:03 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js

index 05b68f50cbac3126d05d6f0ffd60e0341e99104d..d774fb5849be03884691262c6d39c90b7cbb8e24 100644 (file)
@@ -37,6 +37,39 @@ $.Redactor.prototype.WoltLabKeydown = function() {
                                if (isBlockquote) this.keydown.blockquote = isBlockquote;
                        }).bind(this);
                        
+                       this.keydown.replaceToParagraph = (function(tag) {
+                               var blockElem = this.selection.block();
+                               
+                               var blockHtml = blockElem.innerHTML.replace(/<br\s?\/?>/gi, '');
+                               if (blockElem.tagName === tag && this.utils.isEmpty(blockHtml) && !$(blockElem).hasClass('redactor-in'))
+                               {
+                                       var p = document.createElement('p');
+                                       $(blockElem).replaceWith(p);
+                                       
+                                       // caret to p
+                                       var range = document.createRange();
+                                       range.setStart(p, 0);
+                                       
+                                       var textNode = document.createTextNode('\u200B');
+                                       
+                                       range.insertNode(textNode);
+                                       range.setStartAfter(textNode);
+                                       range.collapse(true);
+                                       
+                                       var sel = window.getSelection();
+                                       sel.removeAllRanges();
+                                       sel.addRange(range);
+                                       
+                                       return false;
+                               }
+                               else if (blockElem.tagName === 'P')
+                               {
+                                       // WoltLab modification: do not remove class, preserving
+                                       // text alignment
+                                       $(blockElem)/*.removeAttr('class')*/.removeAttr('style');
+                               }
+                       }).bind(this);
+                       
                        this.keydown.onShiftEnter = (function(e) {
                                this.buffer.set();