Make WordPress Core

Ticket #29492: 29492.2.patch

File 29492.2.patch, 1.9 KB (added by azaozz, 11 years ago)
  • src/wp-admin/js/editor-expand.js

     
    3131                        fixedSideTop = false,
    3232                        fixedSideBottom = false,
    3333                        scrollTimer,
     34                        scrollRatio = 0,
    3435                        lastScrollPosition = 0,
    3536                        pageYOffsetAtTop = 130,
    3637                        pinnedToolsTop = 56,
     
    255256                                setTimeout( function() {
    256257                                        editor.execCommand( 'wpAutoResize' );
    257258                                        adjust();
     259
     260                                        if ( scrollRatio ) {
     261                                                window.scrollTo( window.pageXOffset, $document.height() * scrollRatio );
     262                                                scrollRatio = 0;
     263                                        }
    258264                                }, 300 );
    259265                        }
    260266
     
    270276
    271277                                        textEditorResize();
    272278                                        adjust();
     279
     280                                        if ( scrollRatio ) {
     281                                                window.scrollTo( window.pageXOffset, $document.height() * scrollRatio );
     282                                                scrollRatio = 0;
     283                                        }
    273284                                }, 100 );
    274285
    275286                                adjust();
     
    622633                        scrollTimer = setTimeout( adjust, 100 );
    623634                }
    624635
     636                function getScrollRatio() {
     637                        if ( lastScrollPosition ) {
     638                                scrollRatio = lastScrollPosition / $document.height();
     639                        } else {
     640                                scrollRatio = 0;
     641                        }
     642                }
     643
    625644                function on() {
    626645                        // Scroll to the top when triggering this from JS.
    627646                        // Ensures toolbars are pinned properly.
     
    629648                                window.scrollTo( window.pageXOffset, 0 );
    630649                        }
    631650
    632                         $wrap.addClass( 'wp-editor-expand' );
     651                        $wrap.addClass( 'wp-editor-expand' ).on( 'mousedown.editor-expand', '.wp-switch-editor', getScrollRatio );
    633652
    634653                        // Adjust when the window is scrolled or resized.
    635654                        $window.on( 'scroll.editor-expand resize.editor-expand', function( event ) {
     
    690709                                window.scrollTo( window.pageXOffset, 0 );
    691710                        }
    692711
    693                         $wrap.removeClass( 'wp-editor-expand' );
     712                        $wrap.removeClass( 'wp-editor-expand' ).off( 'mousedown.editor-expand' );
    694713
    695714                        $window.off( '.editor-expand' );
    696715                        $document.off( '.editor-expand' );