Admin menu:

- Fix scrolling the pinned menu with a mouse wheel.
- Fix pinning when the menu is only slightly taller than the viewport.
- Disable pinning on IE8, updating CSS top makes it jump when scrolling with a mouse wheel.
See #29806
Built from https://develop.svn.wordpress.org/trunk@29978


git-svn-id: http://core.svn.wordpress.org/trunk@29724 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-10-21 06:12:20 +00:00
parent 2c8e435aa5
commit ecdc8d3baf
3 changed files with 43 additions and 22 deletions

View File

@ -177,6 +177,7 @@ $(document).ready( function() {
currentPage = pageInput.val(), currentPage = pageInput.val(),
isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ), isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ),
isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1, isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1,
isIE8 = $( document.documentElement ).hasClass( 'ie8' ),
$document = $( document ), $document = $( document ),
$window = $( window ), $window = $( window ),
$body = $( document.body ), $body = $( document.body ),
@ -195,6 +196,7 @@ $(document).ready( function() {
menuTop = 0, menuTop = 0,
height = { height = {
window: $window.height(), window: $window.height(),
wpwrap: $wpwrap.height(),
adminbar: $adminbar.height(), adminbar: $adminbar.height(),
menu: $adminMenuWrap.height() menu: $adminMenuWrap.height()
}; };
@ -535,7 +537,12 @@ $(document).ready( function() {
function pinMenu() { function pinMenu() {
var windowPos = $window.scrollTop(); var windowPos = $window.scrollTop();
if ( isIOS || $adminmenu.data('wp-responsive') ) { if ( isIOS || isIE8 || $adminmenu.data( 'wp-responsive' ) ) {
return;
}
if ( height.menu + height.adminbar + 20 > height.wpwrap ) { // 20px "buffer"
unpinMenu();
return; return;
} }
@ -545,7 +552,11 @@ $(document).ready( function() {
if ( pinnedMenuTop ) { if ( pinnedMenuTop ) {
// let it scroll // let it scroll
pinnedMenuTop = false; pinnedMenuTop = false;
menuTop = $adminMenuWrap.offset().top - height.adminbar; menuTop = $adminMenuWrap.offset().top - height.adminbar - ( windowPos - lastScrollPosition );
if ( menuTop + height.menu + height.adminbar < windowPos + height.window ) {
menuTop = windowPos + height.window - height.menu - height.adminbar;
}
$adminMenuWrap.css({ $adminMenuWrap.css({
position: 'absolute', position: 'absolute',
@ -567,7 +578,11 @@ $(document).ready( function() {
if ( pinnedMenuBottom ) { if ( pinnedMenuBottom ) {
// let it scroll // let it scroll
pinnedMenuBottom = false; pinnedMenuBottom = false;
menuTop = $adminMenuWrap.offset().top - height.adminbar; menuTop = $adminMenuWrap.offset().top - height.adminbar + ( lastScrollPosition - windowPos );
if ( menuTop + height.menu > windowPos + height.window ) {
menuTop = windowPos;
}
$adminMenuWrap.css({ $adminMenuWrap.css({
position: 'absolute', position: 'absolute',
@ -587,13 +602,17 @@ $(document).ready( function() {
} else { } else {
// Resizing // Resizing
pinnedMenuTop = pinnedMenuBottom = false; pinnedMenuTop = pinnedMenuBottom = false;
menuTop = $adminMenuWrap.offset().top - height.adminbar; menuTop = windowPos + height.window - height.menu - height.adminbar - 1;
$adminMenuWrap.css({ if ( menuTop > 0 ) {
position: 'absolute', $adminMenuWrap.css({
top: menuTop, position: 'absolute',
bottom: '' top: menuTop,
}); bottom: ''
});
} else {
unpinMenu();
}
} }
} }
@ -626,21 +645,10 @@ $(document).ready( function() {
} }
} }
setPinMenu();
if ( ! isIOS ) { if ( ! isIOS ) {
$window.on( 'scroll.pin-menu', pinMenu ); $window.on( 'scroll.pin-menu', pinMenu );
} }
$document.on( 'wp-window-resized.pin-menu', function() {
height.window = $window.height();
height.adminbar = $adminbar.height();
setPinMenu();
}).on( 'wp-collapse-menu.pin-menu', function() {
height.menu = $adminMenuWrap.height();
setPinMenu();
});
window.wpResponsive = { window.wpResponsive = {
init: function() { init: function() {
var self = this; var self = this;
@ -775,6 +783,19 @@ $(document).ready( function() {
}; };
window.wpResponsive.init(); window.wpResponsive.init();
setPinMenu();
$document.on( 'wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu', function() {
height.wpwrap = $wpwrap.height();
height.window = $window.height();
height.adminbar = $adminbar.height();
setPinMenu();
}).on( 'wp-collapse-menu.pin-menu', function() {
height.wpwrap = $wpwrap.height();
height.menu = $adminMenuWrap.height();
setPinMenu();
});
}); });
// Fire a custom jQuery event at the end of window resize // Fire a custom jQuery event at the end of window resize

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.1-alpha-20141020'; $wp_version = '4.1-alpha-20141021';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.