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