Make WordPress Core

Ticket #29492: 29492.patch

File 29492.patch, 3.6 KB (added by iseulde, 9 years ago)
  • src/wp-admin/js/editor-expand.js

     
    161161                                return;
    162162                        }
    163163
     164                        editor.show = function() {
     165                                this.fire( 'beforeShow' );
     166                                Object.getPrototypeOf( editor ).show.apply( this, arguments );
     167                        };
     168
     169                        editor.hide = function() {
     170                                this.fire( 'beforeHide' );
     171                                Object.getPrototypeOf( editor ).hide.apply( this, arguments );
     172                        };
     173
    164174                        // Copy the editor instance.
    165175                        mceEditor = editor;
    166176
     
    248258                                }
    249259                        }
    250260
    251                         // Adjust when switching editor modes.
    252                         function mceShow() {
    253                                 $window.on( 'scroll.mce-float-panels', hideFloatPanels );
     261                        function mceBeforeShow() {
     262                                var height = $textEditor.height(),
     263                                        scrollTop = $window.scrollTop(),
     264                                        scrollEditorTop = scrollTop - $textEditor.offset().top +
     265                                                heights.adminBarHeight + heights.toolsHeight + heights.textTopHeight,
     266                                        percentageScrolled = scrollEditorTop / height;
     267
     268                                editor.once( 'show', function() {
     269                                        setTimeout( function() {
     270                                                editor.execCommand( 'wpAutoResize' );
     271                                                adjust();
    254272
    255                                 setTimeout( function() {
    256                                         editor.execCommand( 'wpAutoResize' );
    257                                         adjust();
    258                                 }, 300 );
     273                                                if ( percentageScrolled > 0 ) {
     274                                                        height = $visualEditor.height(),
     275                                                        scrollEditorTop = Math.round( height * percentageScrolled );
     276                                                        scrollTop = scrollEditorTop + $visualEditor.offset().top -
     277                                                                ( heights.adminBarHeight + heights.toolsHeight );
     278
     279                                                        $window.scrollTop( scrollTop );
     280                                                }
     281                                        }, 300 );
     282                                } );
    259283                        }
    260284
    261                         function mceHide() {
    262                                 $window.off( 'scroll.mce-float-panels' );
     285                        function mceBeforeHide() {
     286                                var height = $visualEditor.height(),
     287                                        scrollTop = $window.scrollTop(),
     288                                        scrollEditorTop = scrollTop - $visualEditor.offset().top +
     289                                                heights.adminBarHeight + heights.toolsHeight,
     290                                        percentageScrolled = scrollEditorTop / height;
    263291
    264                                 setTimeout( function() {
    265                                         var top = $contentWrap.offset().top;
     292                                editor.once( 'hide', function() {
     293                                        setTimeout( function() {
     294                                                textEditorResize();
     295                                                adjust();
    266296
    267                                         if ( window.pageYOffset > top ) {
    268                                                 window.scrollTo( window.pageXOffset, top - heights.adminBarHeight );
    269                                         }
     297                                                if ( percentageScrolled > 0 ) {
     298                                                        height = $textEditor.height(),
     299                                                        scrollEditorTop = Math.round( height * percentageScrolled );
     300                                                        scrollTop = scrollEditorTop + $textEditor.offset().top -
     301                                                                ( heights.adminBarHeight + heights.toolsHeight + heights.textTopHeight );
    270302
    271                                         textEditorResize();
    272                                         adjust();
    273                                 }, 100 );
     303                                                        $window.scrollTop( scrollTop );
     304                                                }
     305                                        }, 100 );
    274306
    275                                 adjust();
     307                                        adjust();
     308                                } );
    276309                        }
    277310
    278311                        function toggleAdvanced() {
     
    281314
    282315                        mceBind = function() {
    283316                                editor.on( 'keyup', mceKeyup );
    284                                 editor.on( 'show', mceShow );
    285                                 editor.on( 'hide', mceHide );
     317                                editor.on( 'beforeShow', mceBeforeShow );
     318                                editor.on( 'beforeHide', mceBeforeHide );
    286319                                editor.on( 'wp-toolbar-toggle', toggleAdvanced );
    287320                                // Adjust when the editor resizes.
    288321                                editor.on( 'setcontent wp-autoresize wp-toolbar-toggle', adjust );
     
    296329
    297330                        mceUnbind = function() {
    298331                                editor.off( 'keyup', mceKeyup );
    299                                 editor.off( 'show', mceShow );
    300                                 editor.off( 'hide', mceHide );
     332                                editor.off( 'beforeShow', mceBeforeShow );
     333                                editor.off( 'beforeHide', mceBeforeHide );
    301334                                editor.off( 'wp-toolbar-toggle', toggleAdvanced );
    302335                                editor.off( 'setcontent wp-autoresize wp-toolbar-toggle', adjust );
    303336                                editor.off( 'undo redo', mceScroll );