Strip links after return key in Firefox
authorAlexander Ebert <ebert@woltlab.com>
Tue, 20 Dec 2016 12:00:04 +0000 (13:00 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 20 Dec 2016 12:00:11 +0000 (13:00 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js

index 97298981b96687812984bd05931e417503ded206..7df1da8fd319adecb0a11df291bce621f62f102b 100644 (file)
@@ -105,6 +105,45 @@ $.Redactor.prototype.WoltLabKeydown = function() {
                                // firefox enter into inline element
                                if (this.detect.isFirefox() && this.utils.isInline(this.keydown.parent)) {
                                        this.keydown.insertBreakLine(e);
+                                       
+                                       // WoltLab modification: strip links on return
+                                       setTimeout((function () {
+                                               var block = this.selection.block();
+                                               var current = this.selection.inline();
+                                               
+                                               while (current && current !== block) {
+                                                       if (current.nodeName === 'A') {
+                                                               // check if this is an empty link
+                                                               var remove = false;
+                                                               if (current.childNodes.length === 0) {
+                                                                       remove = true;
+                                                               }
+                                                               else if (current.textContent.replace(/\u200B/g, '') === '') {
+                                                                       remove = true;
+                                                                       
+                                                                       // check if there are only <span> elements
+                                                                       elBySelAll('*', current, function (element) {
+                                                                               if (element.nodeName !== 'SPAN') {
+                                                                                       remove = false;
+                                                                               }
+                                                                       });
+                                                               }
+                                                               
+                                                               if (remove) {
+                                                                       while (current.childNodes.length) {
+                                                                               current.parentNode.insertBefore(current.childNodes[0], current);
+                                                                       }
+                                                                       
+                                                                       elRemove(current);
+                                                                       
+                                                                       break;
+                                                               }
+                                                       }
+                                                       
+                                                       current = current.parentNode;
+                                               }
+                                       }).bind(this), 1);
+                                       
                                        return;
                                }