From deb5337d7c5a465ece75bb6fcf597a90e0d15cc1 Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Fri, 12 Dec 2014 23:59:22 +0000 Subject: [PATCH] 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 --- wp-content/themes/twentyfifteen/functions.php | 2 +- .../themes/twentyfifteen/js/functions.js | 52 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/wp-content/themes/twentyfifteen/functions.php b/wp-content/themes/twentyfifteen/functions.php index 4cc448ca34..5360451e71 100644 --- a/wp-content/themes/twentyfifteen/functions.php +++ b/wp-content/themes/twentyfifteen/functions.php @@ -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-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( 'expand' => '' . esc_html__( 'expand child menu', 'twentyfifteen' ) . '', 'collapse' => '' . esc_html__( 'collapse child menu', 'twentyfifteen' ) . '', diff --git a/wp-content/themes/twentyfifteen/js/functions.js b/wp-content/themes/twentyfifteen/js/functions.js index c4ff8d7683..6610757eb0 100644 --- a/wp-content/themes/twentyfifteen/js/functions.js +++ b/wp-content/themes/twentyfifteen/js/functions.js @@ -66,35 +66,37 @@ function scroll() { var windowPos = $window.scrollTop(); - if ( 955 <= windowWidth && sidebarHeight + adminbarOffset < bodyHeight ) { - if ( sidebarHeight + adminbarOffset > windowHeight ) { - if ( windowPos > lastWindowPos ) { - if ( top ) { - top = false; - topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0; - $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' ); - } else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top ) { - bottom = true; - $sidebar.attr( 'style', 'position: fixed;bottom: 0;' ); - } - } else if ( windowPos < lastWindowPos ) { - if ( bottom ) { - bottom = false; - topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0; - $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' ); - } else if ( ! top && windowPos + adminbarOffset < $sidebar.offset().top ) { - top = true; - $sidebar.attr( 'style', 'position: fixed;' ); - } - } else { - top = bottom = false; + if ( 955 > windowWidth ) { + return; + } + + if ( sidebarHeight + adminbarOffset > windowHeight ) { + if ( windowPos > lastWindowPos ) { + if ( top ) { + top = false; topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0; $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' ); + } else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top && sidebarHeight + adminbarOffset < bodyHeight ) { + bottom = true; + $sidebar.attr( 'style', 'position: fixed; bottom: 0;' ); } - } else if ( ! top ) { - top = true; - $sidebar.attr( 'style', 'position: fixed;' ); + } else if ( windowPos < lastWindowPos ) { + if ( bottom ) { + bottom = false; + topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0; + $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' ); + } else if ( ! top && windowPos + adminbarOffset < $sidebar.offset().top ) { + top = true; + $sidebar.attr( 'style', 'position: fixed;' ); + } + } else { + top = bottom = false; + topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0; + $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' ); } + } else if ( ! top ) { + top = true; + $sidebar.attr( 'style', 'position: fixed;' ); } lastWindowPos = windowPos;