Make WordPress Core

Changeset 29693


Ignore:
Timestamp:
09/03/2014 09:57:56 AM (11 years ago)
Author:
helen
Message:

Editor scrolling: Remember and restore scroll position for visual and text modes.

This prevents the editor from jumping off screen when the rendered visual content is significantly taller than plain text, e.g. when there are views present.

This is also a close restoration of 3.9 behavior, some of which was browser-specific.

props avryl.
fixes #29338.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/editor-expand.js

    r29692 r29693  
    3232        scrollTimer,
    3333        lastScrollPosition = 0,
     34        visualEditorScrollPosition = 0,
     35        textEditorScrollPosition = 0,
    3436        pageYOffsetAtTop = 130,
    3537        pinnedToolsTop = 56,
     
    225227        // Adjust when switching editor modes.
    226228        function mceShow() {
     229            textEditorScrollPosition = window.pageYOffset;
     230
    227231            setTimeout( function() {
     232                var top = $contentWrap.offset().top;
     233
     234                if ( window.pageYOffset > top || visualEditorScrollPosition ) {
     235                    window.scrollTo( window.pageXOffset, visualEditorScrollPosition ? visualEditorScrollPosition : top - heights.adminBarHeight );
     236                }
     237
    228238                editor.execCommand( 'wpAutoResize' );
    229239                adjust();
    230240            }, 300 );
     241
     242            adjust();
    231243        }
    232244
    233245        function mceHide() {
    234             var wrapHeight = $( '#wpwrap' ).height();
    235 
    236             textEditorResize();
    237 
    238             if ( wrapHeight && $window.scrollTop() > wrapHeight ) {
    239                 window.scrollTo( window.pageXOffset, wrapHeight - 1 );
    240             }
     246            visualEditorScrollPosition = window.pageYOffset;
     247
     248            setTimeout( function() {
     249                var top = $contentWrap.offset().top;
     250
     251                if ( window.pageYOffset > top || textEditorScrollPosition ) {
     252                    window.scrollTo( window.pageXOffset, textEditorScrollPosition ? textEditorScrollPosition : top - heights.adminBarHeight );
     253                }
     254
     255                textEditorResize();
     256                adjust();
     257            }, 100 );
    241258
    242259            adjust();
Note: See TracChangeset for help on using the changeset viewer.