Twenty Fifteen: update scroll functionality to make sure child menu items are always reachable.

Props iamtakashi, fixes #30674.
Built from https://develop.svn.wordpress.org/trunk@30838


git-svn-id: http://core.svn.wordpress.org/trunk@30828 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Lance Willett 2014-12-12 23:59:22 +00:00
parent bb67aa9d5a
commit deb5337d7c
2 changed files with 28 additions and 26 deletions

View File

@ -226,7 +226,7 @@ function twentyfifteen_scripts() {
wp_enqueue_script( 'twentyfifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20141010' ); wp_enqueue_script( 'twentyfifteen-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20141010' );
} }
wp_enqueue_script( 'twentyfifteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20141010', true ); wp_enqueue_script( 'twentyfifteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20141212', true );
wp_localize_script( 'twentyfifteen-script', 'screenReaderText', array( wp_localize_script( 'twentyfifteen-script', 'screenReaderText', array(
'expand' => '<span class="screen-reader-text">' . esc_html__( 'expand child menu', 'twentyfifteen' ) . '</span>', 'expand' => '<span class="screen-reader-text">' . esc_html__( 'expand child menu', 'twentyfifteen' ) . '</span>',
'collapse' => '<span class="screen-reader-text">' . esc_html__( 'collapse child menu', 'twentyfifteen' ) . '</span>', 'collapse' => '<span class="screen-reader-text">' . esc_html__( 'collapse child menu', 'twentyfifteen' ) . '</span>',

View File

@ -66,14 +66,17 @@
function scroll() { function scroll() {
var windowPos = $window.scrollTop(); var windowPos = $window.scrollTop();
if ( 955 <= windowWidth && sidebarHeight + adminbarOffset < bodyHeight ) { if ( 955 > windowWidth ) {
return;
}
if ( sidebarHeight + adminbarOffset > windowHeight ) { if ( sidebarHeight + adminbarOffset > windowHeight ) {
if ( windowPos > lastWindowPos ) { if ( windowPos > lastWindowPos ) {
if ( top ) { if ( top ) {
top = false; top = false;
topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0; topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;
$sidebar.attr( 'style', 'top: ' + topOffset + 'px;' ); $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );
} else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top ) { } else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top && sidebarHeight + adminbarOffset < bodyHeight ) {
bottom = true; bottom = true;
$sidebar.attr( 'style', 'position: fixed; bottom: 0;' ); $sidebar.attr( 'style', 'position: fixed; bottom: 0;' );
} }
@ -95,7 +98,6 @@
top = true; top = true;
$sidebar.attr( 'style', 'position: fixed;' ); $sidebar.attr( 'style', 'position: fixed;' );
} }
}
lastWindowPos = windowPos; lastWindowPos = windowPos;
} }