keyboard-image-navigation.js 516 B

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