Added workaround for superflous newlines in Firefox
authorAlexander Ebert <ebert@woltlab.com>
Fri, 16 Oct 2015 11:21:36 +0000 (13:21 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 16 Oct 2015 11:21:36 +0000 (13:21 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js

index 232026cf55ac8ec0c4e51e0928251d7ac5dcf116..92b6287cb002e9fe2ed7df7b3b1b7c9ac9d1ca70 100644 (file)
@@ -2308,6 +2308,23 @@ RedactorPlugins.wbbcode = function() {
                                this.selection.get();
                                var $selectedText = this.selection.getText();
                                
+                               if ($.browser.mozilla) {
+                                       // window.getSelection().toString() returns superflous newlines
+                                       $selectedText = $selectedText.replace(/\r/g,  '').replace(/\u200b/g, '');
+                                       $selectedText = $selectedText.replace(/(\n+)/g, function(match, newlines) {
+                                               var count = newlines.match(/\n/g).length;
+                                               count = ~~(count / 2);
+                                               
+                                               newlines = '';
+                                               while (count > 0) {
+                                                       newlines += "\n";
+                                                       count--;
+                                               }
+                                               
+                                               return newlines;
+                                       });
+                               }
+                               
                                this.selection.save();
                                this.modal.show();