Fixed browsers creating invalid HTML when indenting the first item
authorAlexander Ebert <ebert@woltlab.com>
Mon, 2 Mar 2015 11:58:42 +0000 (12:58 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 2 Mar 2015 11:58:42 +0000 (12:58 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 6a136402c27d6618e3c92c7ab67a87a9dc7d8216..54c1f1894ade590f25afc366af728508f493cfd5 100644 (file)
@@ -30,6 +30,7 @@ RedactorPlugins.wmonkeypatch = function() {
                        this.wmonkeypatch.code();
                        this.wmonkeypatch.dropdown();
                        this.wmonkeypatch.image();
+                       this.wmonkeypatch.indent();
                        this.wmonkeypatch.inline();
                        this.wmonkeypatch.insert();
                        this.wmonkeypatch.keydown();
@@ -637,6 +638,25 @@ RedactorPlugins.wmonkeypatch = function() {
                        }).bind(this);
                },
                
+               /**
+                * Partially overwrites the 'indent' module.
+                * 
+                *  - prevent browsers from screwing up the DOM when indenting the only item
+                */
+               indent: function() {
+                       // indent.increaseLists
+                       var $mpIncrease = this.indent.increase;
+                       this.indent.increase = (function() {
+                               var $block = this.selection.getBlock();
+                               if ($block && $block.tagName === 'LI') {
+                                       // do not allow indenting the first list item because it yields invalid HTML
+                                       if ($block.parentElement.firstChild !== $block) {
+                                               $mpIncrease.call(this);
+                                       }
+                               }
+                       }).bind(this);
+               },
+               
                /**
                 * Partially overwrites the 'inline' module.
                 *