/* global business_office_l10n */
/**
 * Theme functions file.
 *
 * Contains handlers for navigation and widget area.
 */

// Menus 
function business_office_menu_open_nav() {
    jQuery(".sidenav").addClass('show');
  }
  function business_office_menu_close_nav() {
    jQuery(".sidenav").removeClass('show');
  }
  
  ( function( window, document ) {
    function business_office_keepFocusInMenu() {
      document.addEventListener( 'keydown', function( e ) {
        const business_office_nav = document.querySelector( '.sidenav' );
  
        if ( ! business_office_nav || ! business_office_nav.classList.contains( 'show' ) ) {
          return;
        }
        const elements = [...business_office_nav.querySelectorAll( 'input, a, button' )],
          business_office_lastEl = elements[ elements.length - 1 ],
          business_office_firstEl = elements[0],
          business_office_activeEl = document.activeElement,
          tabKey = e.keyCode === 9,
          shiftKey = e.shiftKey;
  
        if ( ! shiftKey && tabKey && business_office_lastEl === business_office_activeEl ) {
          e.preventDefault();
          business_office_firstEl.focus();
        }
  
        if ( shiftKey && tabKey && business_office_firstEl === business_office_activeEl ) {
          e.preventDefault();
          business_office_lastEl.focus();
        }
      } );
    }
    business_office_keepFocusInMenu();
  } )( window, document );