Fixed modifying link text on insert
authorAlexander Ebert <ebert@woltlab.com>
Tue, 6 Jan 2015 14:49:22 +0000 (15:49 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 6 Jan 2015 14:49:22 +0000 (15:49 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index bd3f27ffa5b70bda42f6d69fa715dfad188f281b..78bf3f02e334f57e00dd057a281fe15f849d4026 100644 (file)
@@ -648,10 +648,33 @@ RedactorPlugins.wmonkeypatch = function() {
                                
                                this.selection.get();
                                var $current = this.selection.getCurrent();
+                               if ($current.nodeType === Node.TEXT_NODE) {
+                                       $current = $current.parentElement;
+                               }
+                               
                                if ($current.tagName === 'A') {
                                        this.caret.setAfter($current);
                                }
                        }).bind(this);
+                       
+                       // link.set
+                       var $mpSet = this.link.set;
+                       this.link.set = (function(text, link, target) {
+                               $mpSet.call(this, text, link, target);
+                               
+                               if (text.length && this.link.text !== text) {
+                                       this.selection.get();
+                                       
+                                       var $current = this.selection.getCurrent();
+                                       if ($current.nodeType === Node.TEXT_NODE) {
+                                               $current = $current.parentElement;
+                                       }
+                                       
+                                       if ($current.tagName === 'A') {
+                                               $($current).text(text);
+                                       }
+                               }
+                       }).bind(this);
                },
                
                /**