From 70d210a135e893afdb77f6a1aa1ef074e5ad4db2 Mon Sep 17 00:00:00 2001 From: Joe Anzalone Date: Tue, 15 Jan 2013 15:31:14 -0500 Subject: [PATCH] Update input focus when visual focus changes using JavaScript --- functions.php | 2 ++ js/skip-link-focus-fix.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 js/skip-link-focus-fix.js diff --git a/functions.php b/functions.php index 89e9eb7814..2bd760d5cb 100644 --- a/functions.php +++ b/functions.php @@ -103,6 +103,8 @@ function _s_scripts() { wp_enqueue_style( 'style', get_stylesheet_uri() ); wp_enqueue_script( 'small-menu', get_template_directory_uri() . '/js/small-menu.js', array( 'jquery' ), '20120206', true ); + + wp_enqueue_script( 'skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array( 'jquery' ), '20130115', true ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); diff --git a/js/skip-link-focus-fix.js b/js/skip-link-focus-fix.js new file mode 100644 index 0000000000..f68f885ea1 --- /dev/null +++ b/js/skip-link-focus-fix.js @@ -0,0 +1,23 @@ +/** + * Based on JavaScript by Nicholas C. Zakas + * http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/ + */ + +( function( $ ) { + +$( window ).bind( 'hashchange', function() { + + var element = document.getElementById( location.hash.substring( 1 ) ); + + if ( element ) { + + if ( ! /^(?:a|select|input|button)$/i.test( element.tagName ) ) { + element.tabIndex = -1; + } + + element.focus(); + } + +}); + +})( jQuery ); \ No newline at end of file