[BUGFIX] Only focus RTE if current focus is on body tag 28/47528/8
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 7 Apr 2016 08:09:44 +0000 (10:09 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Fri, 6 May 2016 07:56:44 +0000 (09:56 +0200)
Focus the RTE (or its textarea fallback) only if the current focus
is on the body tag, which is the default after loading a page.
This prevents focus stealing if the focus is e.g. on an input field
before the RTE was initialized.

Resolves: #72900
Releases: master, 7.6
Change-Id: I238cd0ce1972f41e451ace674eeff350690cb427
Reviewed-on: https://review.typo3.org/47528
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Editor/Editor.js

index 1acf5b8..be68561 100644 (file)
@@ -506,6 +506,11 @@ define(['TYPO3/CMS/Rtehtmlarea/HTMLArea/UserAgent/UserAgent',
         * Focus on the editor
         */
        Editor.prototype.focus = function () {
+               if (document.activeElement.tagName.toLowerCase() !== 'body') {
+                       // Only focus the editor if the body tag is focused, which is
+                       // the default after loading a page
+                       return;
+               }
                switch (this.getMode()) {
                        case 'wysiwyg':
                                this.iframe.focus();