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