Fixed NS_ERROR_FAILURE in Firefox related to code.showCode()
authorAlexander Ebert <ebert@woltlab.com>
Tue, 25 Nov 2014 18:25:14 +0000 (19:25 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 25 Nov 2014 18:25:14 +0000 (19:25 +0100)
Invoking setSelectionRange() on a <textarea> contained in a hidden element (display: none) will invoke NS_ERROR_FAILURE without any further error message. This is an attempt to work around by code.showCode() which is unaware of this fact.

wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index b686f3a80ca553330f795c4364484b1c0d1ac1db..ea4cd16e1f8adce0b34e19662ad028d59832fedd 100644 (file)
@@ -277,6 +277,23 @@ RedactorPlugins.wmonkeypatch = function() {
                                
                                return $mpTextareaIndenting.call(this, e);
                        }).bind(this);
+                       
+                       // code.showCode
+                       // fixes an issue related to setSelectionRange on a hidden textarea in Firefox (NS_ERROR_FAILURE, #1984)
+                       var $mpShowCode = this.code.showCode;
+                       this.code.showCode = (function() {
+                               var $hiddenParent = null;
+                               if (!this.$textarea.is(':visible')) {
+                                       $hiddenParent = this.$textarea.parentsUntil(':visible').last();
+                                       $hiddenParent.show();
+                               }
+                               
+                               $mpShowCode.call(this);
+                               
+                               if ($hiddenParent !== null) {
+                                       $hiddenParent.hide();
+                               }
+                       }).bind(this);
                },
                
                /**