home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-content / themes / twentysixteen / js / keyboard-image-navigation.js < prev    next >
Encoding:
Text File  |  2017-05-30  |  527 b   |  27 lines

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