( function( window, document ) {
  function multipurpose_sports_club_keepFocusInMenu() {
    document.addEventListener( 'keydown', function( e ) {
      const multipurpose_sports_club_nav = document.querySelector( '.sidenav' );
      if ( ! multipurpose_sports_club_nav || ! multipurpose_sports_club_nav.classList.contains( 'open' ) ) {
        return;
      }
      const elements = [...multipurpose_sports_club_nav.querySelectorAll( 'input, a, button' )],
        multipurpose_sports_club_lastEl = elements[ elements.length - 1 ],
        multipurpose_sports_club_firstEl = elements[0],
        multipurpose_sports_club_activeEl = document.activeElement,
        tabKey = e.keyCode === 9,
        shiftKey = e.shiftKey;
      if ( ! shiftKey && tabKey && multipurpose_sports_club_lastEl === multipurpose_sports_club_activeEl ) {
        e.preventDefault();
        multipurpose_sports_club_firstEl.focus();
      }
      if ( shiftKey && tabKey && multipurpose_sports_club_firstEl === multipurpose_sports_club_activeEl ) {
        e.preventDefault();
        multipurpose_sports_club_lastEl.focus();
      }
    } );
  }
  multipurpose_sports_club_keepFocusInMenu();
} )( window, document );