Removing markers can yield empty text nodes, slowing down rendering
authorAlexander Ebert <ebert@woltlab.com>
Sat, 27 Dec 2014 11:46:57 +0000 (12:46 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 27 Dec 2014 11:46:57 +0000 (12:46 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index bdacccb90618a53c068b508dc24d85302699df8a..7043fbd9a280292e5a896ed6eaade824b6d562c1 100644 (file)
@@ -36,6 +36,7 @@ RedactorPlugins.wmonkeypatch = function() {
                        this.wmonkeypatch.modal();
                        this.wmonkeypatch.paste();
                        this.wmonkeypatch.observe();
+                       this.wmonkeypatch.selection();
                        this.wmonkeypatch.utils();
                        
                        // templates
@@ -790,6 +791,25 @@ RedactorPlugins.wmonkeypatch = function() {
                        }).bind(this);
                },
                
+               /**
+                * Partially overwrites the 'selection' module.
+                * 
+                *  - remove superflous empty text nodes caused by the selection markers (#2083)
+                */
+               selection: function() {
+                       // selection.removeMarkers
+                       this.selection.removeMarkers = (function() {
+                               this.$editor.find('span.redactor-selection-marker').each(function(index, marker) {
+                                       var $nextSibling = marker.nextSibling;
+                                       if ($nextSibling !== null && $nextSibling.nodeType === Element.TEXT_NODE && $nextSibling.length === 0) {
+                                               $($nextSibling).remove();
+                                       }
+                                       
+                                       $(marker).remove();
+                               });
+                       }).bind(this);
+               },
+               
                /**
                 * Partially overwrites the 'utils' module.
                 *