[BUGFIX] Automatic scrolling of editing form when inserting paragraph 94/37894/4
authorStanislas Rolland <typo3@sjbr.ca>
Mon, 16 Mar 2015 20:38:55 +0000 (16:38 -0400)
committerAndreas Fernandez <andreas.fernandez@aspedia.de>
Fri, 10 Apr 2015 07:15:18 +0000 (09:15 +0200)
Problem: Entering a new paragraph leads to automatic scrolling of the
editing form in the backend if the cursor is positioned in the last
line of the visible editing area of the RTE.
Solution: Scroll only the iframe window if the caret is not into view.

Releases: master, 6.2
Resolves: #22167
Change-Id: I731e95931ac303f7ab2d7e493ba87d9788a51251
Reviewed-on: http://review.typo3.org/37894
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
Tested-by: Andreas Fernandez <andreas.fernandez@aspedia.de>
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Editor/Editor.js

index 4d6690c..09a7ccc 100644 (file)
@@ -517,13 +517,18 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/Editor/Editor',
         */
        Editor.prototype.scrollToCaret = function () {
                if (!UserAgent.isIE) {
-                       var e = this.getSelection().getParentElement(),
-                               w = this.iframe.getEl().contentWindow ? this.iframe.getEl().contentWindow : window,
-                               h = w.innerHeight || w.height,
-                               d = this.document,
-                               t = d.documentElement.scrollTop || d.body.scrollTop;
-                       if (e.offsetTop > h+t || e.offsetTop < t) {
-                               this.getSelection().getParentElement().scrollIntoView();
+                       var contentWindow = this.iframe.getEl().contentWindow;
+                       if (contentWindow) {
+                               var windowHeight = contentWindow.innerHeight,
+                                       element = this.getSelection().getParentElement(),
+                                       elementOffset = element.offsetTop,
+                                       elementHeight = Dom.getSize(element).height,
+                                       bodyScrollTop = contentWindow.document.body.scrollTop;
+                               // If the current selection is out of view
+                               if (elementOffset > windowHeight + bodyScrollTop || elementOffset < bodyScrollTop) {
+                                       // Scroll the iframe contentWindow
+                                       contentWindow.scrollTo(0, elementOffset - windowHeight + elementHeight);
+                               }
                        }
                }
        };