From 208e443dc5453fb890cf48b248ed8218ff777466 Mon Sep 17 00:00:00 2001 From: Tammie Lister Date: Wed, 9 Nov 2016 16:12:35 +0000 Subject: [PATCH] Twenty Seventeen: Fixes focused controls hidden by top menu. When a page is scrolled, the top nav menu became fixed. This resolves that. Props afercia, Fencer04, davidakennedy Fixes #38476 git-svn-id: https://develop.svn.wordpress.org/trunk@39183 602fd350-edb4-49c9-b593-d223f7449a82 --- .../twentyseventeen/assets/js/global.js | 21 +++++++++++++++++++ .../themes/twentyseventeen/functions.php | 7 ++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/wp-content/themes/twentyseventeen/assets/js/global.js b/src/wp-content/themes/twentyseventeen/assets/js/global.js index de64a9c2d7..cced97c475 100644 --- a/src/wp-content/themes/twentyseventeen/assets/js/global.js +++ b/src/wp-content/themes/twentyseventeen/assets/js/global.js @@ -26,6 +26,27 @@ menuTop = 0, resizeTimer; + /** + * Ensure the sticky navigation doesn't cover current focused links + */ + $( '#content a, #colophon a' ).focus( function() { + if ( $navigation.hasClass( 'site-navigation-fixed' ) ) { + var windowScrollTop = $( window ).scrollTop(), + fixedNavHeight = $navigation.height(), + itemScrollTop = $( this ).offset().top, + offsetDiff = itemScrollTop - windowScrollTop; + + // Account for Admin bar. + if ( $( '#wpadminbar' ).length ) { + offsetDiff -= $( '#wpadminbar' ).height(); + } + + if ( offsetDiff < fixedNavHeight ) { + $( window ).scrollTo( itemScrollTop - ( fixedNavHeight + 50 ), 600); + }; + } + } ); + /** * Sets properties of navigation */ diff --git a/src/wp-content/themes/twentyseventeen/functions.php b/src/wp-content/themes/twentyseventeen/functions.php index 79bfed78d2..de742624a6 100644 --- a/src/wp-content/themes/twentyseventeen/functions.php +++ b/src/wp-content/themes/twentyseventeen/functions.php @@ -379,16 +379,13 @@ function twentyseventeen_scripts() { wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true ); + wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true ); + wp_localize_script( 'twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } - - // Scroll effects (only loaded on front page). - if ( is_front_page() ) { - wp_enqueue_script( 'jquery-scrollto', get_template_directory_uri() . '/assets/js/jquery.scrollTo.js', array( 'jquery' ), '2.1.2', true ); - } } add_action( 'wp_enqueue_scripts', 'twentyseventeen_scripts' );