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