keyboard-image-navigation.js 485 B

12345678910111213141516171819202122
  1. /**
  2. * Twenty Fifteen keyboard support for image navigation.
  3. */
  4. ( function( $ ) {
  5. $( document ).on( 'keydown.twentyfifteen', function( e ) {
  6. var url = false;
  7. // Left arrow key code.
  8. if ( e.which === 37 ) {
  9. url = $( '.nav-previous a' ).attr( 'href' );
  10. // Right arrow key code.
  11. } else if ( e.which === 39 ) {
  12. url = $( '.nav-next a' ).attr( 'href' );
  13. }
  14. if ( url && ( !$( 'textarea, input' ).is( ':focus' ) ) ) {
  15. window.location = url;
  16. }
  17. } );
  18. } )( jQuery );