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' );