// Run ECMAScript in strict mode.
'use strict';

jQuery( () => {

	// Check if the post-type-hdsnav is on the page.
	if ( ! jQuery( 'body' ).hasClass( 'post-type-hdsnav' ) ) {

		// If the secondary navigation "usa-accordion__button" is clicked, change "aria-expanded" to
		// true and remove "hidden" from the "usa-nav__submenu" item directly beneath it.
		jQuery(document).on( 'click', '.hds-secondary-navigation .usa-accordion__button', function() {

			// Before we do this, we need to close any other open submenus.
			// Any submenu that is not this one, and is open, should be closed.
			jQuery( '.hds-secondary-navigation .usa-accordion__button' ).not(this).attr( 'aria-expanded', 'false' );
			jQuery( '.hds-secondary-navigation .usa-accordion__button' ).not(this).next().attr( 'hidden', 'hidden' );

			// Now we can open the submenu that was clicked.
			// Toggle this in case the menu is already open.
			jQuery( this ).attr( 'aria-expanded', function(index, attr) {
				return attr === 'true' ? 'false' : 'true';
			});

			jQuery( this ).next( '.usa-nav__submenu' ).attr( 'hidden', function(index, attr) {
				return attr === 'hidden' ? null : 'hidden';
			});
		});

		// Let's make sure the .hds-secondary-navigation-menu-items is hidden but set to flex.
		jQuery( '.hds-secondary-navigation-menu-items' ).attr( 'hidden', 'hidden' );

		// If the user clicks on the mobile secondary nav trigger, let's open the mobile nav.
		jQuery(document).on( 'click', '.hds-secondary-nav-mobile-button', function() {

			// Add an "is-active" class to both.
			jQuery( this ).toggleClass( 'hds-active' );
			jQuery( '.hds-secondary-navigation-menu-items' ).toggleClass( 'hds-active' );

			// Slide toggle the secondary nav track.
			jQuery( '.hds-secondary-navigation-menu-items' ).slideToggle(300);

			// Toggle the "hidden" attribute on the "hds-secondary-nav-mobile" class.
			jQuery( '.hds-secondary-navigation-menu-items' ).attr( 'hidden', function(index, attr) {
				return attr === 'hidden' ? null : 'hidden';
			});

			// Now, toggle the "hds-secondary-nav-mobile-button" class to aria-expanded.
			jQuery( '.hds-secondary-nav-mobile-button' ).attr( 'aria-expanded', function(index, attr) {
				return attr === 'true' ? 'false' : 'true';
			}
			);
		});
	}
});
;
'use strict';

jQuery( function() {
    //Add Tabbed Section Block jQuery
    jQuery( '.hds-tab-nav-item' ).on( 'click', function( event ) {
        var tab_id = jQuery( this ).attr('data-tab-id');
        jQuery(this).closest('.hds-tabbed-section').find( ".hds-tab-nav-item" ).removeClass('usa-active');
        jQuery(this).closest('.hds-tabbed-section').find( ".hds-tab-nav-item button" ).attr('aria-selected', 'false');
        jQuery(this).closest('.hds-tabbed-section').find( ".hds-tabbed-section-tab" ).removeClass('usa-active');
        jQuery(this).closest('.hds-tabbed-section').find( ".hds-tabbed-section-tab" ).attr('hidden', '');
        jQuery(this).closest('.hds-tabbed-section').find( ".hds-tab-nav-item[data-tab-id="+tab_id+"]" ).addClass('usa-active');
        jQuery(this).closest('.hds-tabbed-section').find( ".hds-tab-nav-item[data-tab-id="+tab_id+"] button" ).attr('aria-selected', 'true');
        jQuery(this).closest('.hds-tabbed-section').find( ".hds-tabbed-section-tab[data-tab-id="+tab_id+"]" ).addClass('usa-active');
        jQuery(this).closest('.hds-tabbed-section').find( ".hds-tabbed-section-tab[data-tab-id="+tab_id+"]" ).removeAttr('hidden');
    });

    jQuery( '.hds-tab-nav-item' ).on( 'keydown', function( event ) {
        var currTab = event.currentTarget;
        var nextTab = jQuery(this).next('li')[0];
        var prevTab = jQuery(this).prev('li')[0];
        var rent = jQuery(this).parent();
        var tabs = rent.children( 'li' );
        var firstTab = tabs[0];
        var lastTab = tabs[tabs.length - 1];
        if (currTab == lastTab) {
            nextTab = firstTab;
        }
        if (currTab == firstTab) {
            prevTab = lastTab;
        }

        var flag = false;
        switch (event.key) {
            case 'ArrowLeft':
                jQuery(prevTab).find('button').focus();
                flag = true;
                break;
            case 'ArrowRight':
                jQuery(nextTab).find('button').focus();
                flag = true;
                break;
            case 'Home':
                jQuery(firstTab).find('button').focus();    
                flag = true;
                break;
            case 'End':
                jQuery(lastTab).find('button').focus();
                flag = true;
                break;
            default:
                break;
        }

        if (flag) {
            event.stopPropagation();
            event.preventDefault();
        }
    });
});;