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