Added a work-around for IE breaking quotes on list insert
authorAlexander Ebert <ebert@woltlab.com>
Tue, 20 Oct 2015 16:33:07 +0000 (18:33 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 20 Oct 2015 16:33:07 +0000 (18:33 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index e7bd0dcda1990d0a6509f09b9499d23ff5c1db26..870cfe9b67e39915a59abd4427758c44b72da037 100644 (file)
@@ -36,6 +36,7 @@ RedactorPlugins.wmonkeypatch = function() {
                        this.wmonkeypatch.keydown();
                        this.wmonkeypatch.keyup();
                        this.wmonkeypatch.link();
+                       this.wmonkeypatch.list();
                        this.wmonkeypatch.modal();
                        this.wmonkeypatch.paste();
                        this.wmonkeypatch.observe();
@@ -959,6 +960,40 @@ RedactorPlugins.wmonkeypatch = function() {
                        }).bind(this);
                },
                
+               /**
+                * Partially overwrites the 'list' module.
+                * 
+                *  - adds a wrapper div before inserting a list to prevent removal of <blockquote> inside quotes
+                */
+               list: function() {
+                       // list.insert
+                       var $mpInsert = this.list.insert;
+                       this.list.insert = (function(cmd) {
+                               var selection = window.getSelection();
+                               if (selection.rangeCount) {
+                                       var range = selection.getRangeAt(0);
+                                       
+                                       if (range.collapsed) {
+                                               var element = range.startContainer;
+                                               if (element.nodeType === Node.TEXT_NODE) {
+                                                       element = element.parentNode;
+                                               }
+                                               
+                                               if (element.nodeName === 'DIV') {
+                                                       if (element.parentNode.nodeName === 'BLOCKQUOTE') {
+                                                               // wrap selection in another div to sabotage Redactor's parent block removal
+                                                               var div = document.createElement('div');
+                                                               element.parentNode.insertBefore(div, element);
+                                                               div.appendChild(element);
+                                                       }
+                                               }
+                                       }
+                               }
+                               
+                               $mpInsert.call(this, cmd);
+                       }).bind(this);
+               },
+               
                /**
                 * Partially overwrites the 'modal' module.
                 *