keyboard-image-navigation.js 531 B

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