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.

Built from https://develop.svn.wordpress.org/trunk@29693


git-svn-id: http://core.svn.wordpress.org/trunk@29468 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2014-09-03 09:58:16 +00:00
parent 0f73f0bea3
commit c8cdcef9be
2 changed files with 23 additions and 6 deletions

View File

@ -31,6 +31,8 @@ jQuery( document ).ready( function($) {
fixedSideBottom = false,
scrollTimer,
lastScrollPosition = 0,
visualEditorScrollPosition = 0,
textEditorScrollPosition = 0,
pageYOffsetAtTop = 130,
pinnedToolsTop = 56,
sidebarBottom = 20,
@ -224,20 +226,35 @@ jQuery( document ).ready( function($) {
// Adjust when switching editor modes.
function mceShow() {
textEditorScrollPosition = window.pageYOffset;
setTimeout( function() {
var top = $contentWrap.offset().top;
if ( window.pageYOffset > top || visualEditorScrollPosition ) {
window.scrollTo( window.pageXOffset, visualEditorScrollPosition ? visualEditorScrollPosition : top - heights.adminBarHeight );
}
editor.execCommand( 'wpAutoResize' );
adjust();
}, 300 );
adjust();
}
function mceHide() {
var wrapHeight = $( '#wpwrap' ).height();
visualEditorScrollPosition = window.pageYOffset;
setTimeout( function() {
var top = $contentWrap.offset().top;
if ( window.pageYOffset > top || textEditorScrollPosition ) {
window.scrollTo( window.pageXOffset, textEditorScrollPosition ? textEditorScrollPosition : top - heights.adminBarHeight );
}
textEditorResize();
if ( wrapHeight && $window.scrollTop() > wrapHeight ) {
window.scrollTo( window.pageXOffset, wrapHeight - 1 );
}
adjust();
}, 100 );
adjust();
}

File diff suppressed because one or more lines are too long