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