/*! This file is auto-generated */
!function(e,t){if("function"==typeof define&&define.amd)define("hoverintent",["module"],t);else if("undefined"!=typeof exports)t(module);else{var n={exports:{}};t(n),e.hoverintent=n.exports}}(this,function(e){"use strict";var t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e};e.exports=function(e,n,o){function i(e,t){return y&&(y=clearTimeout(y)),b=0,p?void 0:o.call(e,t)}function r(e){m=e.clientX,d=e.clientY}function u(e,t){if(y&&(y=clearTimeout(y)),Math.abs(h-m)+Math.abs(E-d)<x.sensitivity)return b=1,p?void 0:n.call(e,t);h=m,E=d,y=setTimeout(function(){u(e,t)},x.interval)}function s(t){return L=!0,y&&(y=clearTimeout(y)),e.removeEventListener("mousemove",r,!1),1!==b&&(h=t.clientX,E=t.clientY,e.addEventListener("mousemove",r,!1),y=setTimeout(function(){u(e,t)},x.interval)),this}function c(t){return L=!1,y&&(y=clearTimeout(y)),e.removeEventListener("mousemove",r,!1),1===b&&(y=setTimeout(function(){i(e,t)},x.timeout)),this}function v(t){L||(p=!0,n.call(e,t))}function a(t){!L&&p&&(p=!1,o.call(e,t))}function f(){e.addEventListener("focus",v,!1),e.addEventListener("blur",a,!1)}function l(){e.removeEventListener("focus",v,!1),e.removeEventListener("blur",a,!1)}var m,d,h,E,L=!1,p=!1,T={},b=0,y=0,x={sensitivity:7,interval:100,timeout:0,handleFocus:!1};return T.options=function(e){var n=e.handleFocus!==x.handleFocus;return x=t({},x,e),n&&(x.handleFocus?f():l()),T},T.remove=function(){e&&(e.removeEventListener("mouseover",s,!1),e.removeEventListener("mouseout",c,!1),l())},e&&(e.addEventListener("mouseover",s,!1),e.addEventListener("mouseout",c,!1)),T}});
;
/*! This file is auto-generated */
!function(l,u,d){function m(e){27===e.which&&(e=w(e.target,".menupop"))&&(e.querySelector(".menupop > .ab-item").focus(),y(e,"hover"))}function f(e){var t;13!==e.which||w(e.target,".ab-sub-wrapper")||(t=w(e.target,".menupop"))&&(e.preventDefault(),(o(t,"hover")?y:b)(t,"hover"))}function p(e){var t;13===e.which&&(t=e.target.getAttribute("href"),-1<d.userAgent.toLowerCase().indexOf("applewebkit"))&&t&&"#"===t.charAt(0)&&setTimeout(function(){var e=l.getElementById(t.replace("#",""));e&&(e.setAttribute("tabIndex","0"),e.focus())},100)}function h(e,t){!w(t.target,".ab-sub-wrapper")&&(t.preventDefault(),t=w(t.target,".menupop"))&&(o(t,"hover")?y:(E(e),b))(t,"hover")}function v(e){var t,n=e.target.parentNode;if(t=n?n.querySelector(".shortlink-input"):t)return e.preventDefault&&e.preventDefault(),e.returnValue=!1,b(n,"selected"),t.focus(),t.select(),!(t.onblur=function(){y(n,"selected")})}function g(){if("sessionStorage"in u)try{for(var e in sessionStorage)-1<e.indexOf("wp-autosave-")&&sessionStorage.removeItem(e)}catch(e){}}function o(e,t){return e&&(e.classList&&e.classList.contains?e.classList.contains(t):e.className&&-1<e.className.split(" ").indexOf(t))}function b(e,t){e&&(e.classList&&e.classList.add?e.classList.add(t):o(e,t)||(e.className&&(e.className+=" "),e.className+=t))}function y(e,t){var n,r;if(e&&o(e,t))if(e.classList&&e.classList.remove)e.classList.remove(t);else{for(n=" "+t+" ",r=" "+e.className+" ";-1<r.indexOf(n);)r=r.replace(n,"");e.className=r.replace(/^[\s]+|[\s]+$/g,"")}}function E(e){if(e&&e.length)for(var t=0;t<e.length;t++)y(e[t],"hover")}function L(e){if(!e.target||"wpadminbar"===e.target.id||"wp-admin-bar-top-secondary"===e.target.id)try{u.scrollTo({top:-32,left:0,behavior:"smooth"})}catch(e){u.scrollTo(0,-32)}}function w(e,t){for(u.Element.prototype.matches||(u.Element.prototype.matches=u.Element.prototype.matchesSelector||u.Element.prototype.mozMatchesSelector||u.Element.prototype.msMatchesSelector||u.Element.prototype.oMatchesSelector||u.Element.prototype.webkitMatchesSelector||function(e){for(var t=(this.document||this.ownerDocument).querySelectorAll(e),n=t.length;0<=--n&&t.item(n)!==this;);return-1<n});e&&e!==l;e=e.parentNode)if(e.matches(t))return e;return null}l.addEventListener("DOMContentLoaded",function(){var n,e,t,r,o,a,s,i,c=l.getElementById("wpadminbar");if(c&&"querySelectorAll"in c){n=c.querySelectorAll("li.menupop"),e=c.querySelectorAll(".ab-item"),t=l.getElementById("wp-admin-bar-logout"),r=l.getElementById("adminbarsearch"),o=l.getElementById("wp-admin-bar-get-shortlink"),a=c.querySelector(".screen-reader-shortcut"),s=/Mobile\/.+Safari/.test(d.userAgent)?"touchstart":"click",y(c,"nojs"),"ontouchstart"in u&&(l.body.addEventListener(s,function(e){w(e.target,"li.menupop")||E(n)}),c.addEventListener("touchstart",function e(){for(var t=0;t<n.length;t++)n[t].addEventListener("click",h.bind(null,n));c.removeEventListener("touchstart",e)})),c.addEventListener("click",L);for(i=0;i<n.length;i++)u.hoverintent(n[i],b.bind(null,n[i],"hover"),y.bind(null,n[i],"hover")).options({timeout:180}),n[i].addEventListener("keydown",f);for(i=0;i<e.length;i++)e[i].addEventListener("keydown",m);r&&((s=l.getElementById("adminbar-search")).addEventListener("focus",function(){b(r,"adminbar-focused")}),s.addEventListener("blur",function(){y(r,"adminbar-focused")})),a&&a.addEventListener("keydown",p),o&&o.addEventListener("click",v),u.location.hash&&u.scrollBy(0,-32),t&&t.addEventListener("click",g)}})}(document,window,navigator);;
( async () => {
	async function postData( url = '', data = {} ) {
		// Default options are marked with *
		const response = await fetch( url, {
			method: 'POST',
			credentials: 'same-origin',
			headers: {
				'Content-Type': 'application/json'
			},
			body: JSON.stringify( { ...data } )
		} );
		return response.json();
	}

	// Indicates whether there's a purge request happening
	let purgeInProgress = false;
	// Stores the ref to the DOM node
	let btn;

	/**
	 * Grab all the necesary URLs (incl. scripts and CSS) for the purge.
	 */
	const getURLsToPurge = () => {
		const fullUrl = document.location.toString();
		const ampURL = ( document.location.origin + document.location.pathname ).replace(/\/$/, '' ) + '/amp/';

		return [ fullUrl, ampURL ].concat(
			Array.from( document.querySelectorAll( 'script[src]' ) ).map( ( { src } ) => src ),
			Array.from( document.querySelectorAll( 'link[rel=stylesheet]' ) ).map( ( { href } ) => href )
		)
			.filter( url => url.includes( document.location.hostname ) );
	}

	/**
	 * Cache purge click handler.
	 * 
	 * @param {Event} e
	 */
	async function onClickHandler( e ) {
		e.preventDefault();

		if ( purgeInProgress ) {
			return;
		}

		let { nonce = '', ajaxurl = '' } = window.VIPPagePurge || {};

		if ( !( nonce && ajaxurl ) ) {
			alert( 'VIP Cache Manager: page cache purging disabled' );
		}

		purgeInProgress = true;

		const urls = getURLsToPurge();

		try {
			const res = await postData( ajaxurl, { nonce, urls } );
			const { success, data } = res;

			btn.textContent = data.result || 'Success';
			btn.disabled = true;
			btn.removeEventListener( 'click', onClickHandler );
		} catch ( err ) {
			purgeInProgress = false;
			btn.textContent = '❌ Cache Purge Failed';
		}
	}

	document.addEventListener( 'DOMContentLoaded', () => {
		btn = document.querySelector( '#wp-admin-bar-vip-purge-page > .ab-item' )
		if ( btn ) {
			btn.addEventListener( 'click', onClickHandler );
		}
	} );

} )();
;
// 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() {
    // Get all the content-lists paginations a tags on the page.
    const contentListsPaginations = jQuery( '.hds-pagination--content-lists' );
    let paginationLinks = contentListsPaginations.find( 'a' );

    // Add click handlers to each of the a tags.
    addClickhandlers( paginationLinks );


    /**
     * Deletes the children of contentList and fadesIn
     * data.html in it's place.Also updates data-current-page to the
     * pageClicked.
     * 
     * @param data: data.html is formatted string of data to insert into the dom
     * @param contentList: Dom element that children will be erased and
     * 'data' will be inserted into as new children.
     * @param pageClicked: int value of the pagination page clicked on.
     *  
     */ 
    function updateBlockData( data, contentList, pageClicked ) {
        // Get all the children items and remove them from the dom.
        const children = jQuery( contentList ).children()
        jQuery( contentList ).children().remove();
        
        // Add the data from the api request.
        jQuery( contentList ).append( data.html ).hide().fadeIn(200); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions

        // Update the current-page data attribute in the content lists block.
        jQuery( contentList ).data( 'current-page', pageClicked );
        jQuery( contentList ).attr( 'data-current-page', pageClicked );
    }


    /**
     * Replaces the DOM content of parentNav in the DOM with new navigation.
     * And recreates the pagination on click handlers on it.
     * 
     * @param data: data.pagination is formatted string of data to insert into the dom
     * @param parentNav: Dom element that holds the pagination items.
     *  
     */
    function updatePagination( data, parentNav ) {    
        const rent = jQuery( parentNav ).parent();
        jQuery( parentNav ).replaceWith( data.pagination ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions
        parentNav = rent.find( 'nav' );

        // Grab the Nav that just changed and add update click handlers.
        const thisPagination = jQuery( parentNav );
        const newPagination = jQuery( thisPagination ).find( 'a' );
        // Add click handlers to the new generated pagination links.
        addClickhandlers( newPagination );
    }


    /**
     *
     * Adds a click handler on all paginationLinks that grabs data from 
     * restEndpoint.endpoint and adds it to the dom. 
     * 
     * @param paginationLinks: list of dom items to add a click handler to
     */
    function addClickhandlers( paginationLinks ) {

        paginationLinks.each(function() {
            // if a function exists delete it.
            jQuery( this ).off("click");

            // add onclick handler.
            jQuery( this ).on( "click", function(e) {
                // prevent any default actions.
                e.preventDefault();
                e.stopPropagation();

                // Get nav parent and hds item sibling.
                const parentNav = jQuery( this ).parent().closest( 'nav' );
                const contentList = jQuery( parentNav ).prev( '.hds-content-items' );
                
                // Get data attributes.
                const postType = contentList.data( 'post-type' );
                const postId = contentList.data( 'post-id' );
                const maxPages = contentList.data( 'max-num-pages' );
                const perPage = contentList.data( 'per-page' );
                const categories = contentList.data( 'categories' );
                const newsTags = contentList.data( 'news-tags' );
                const layout = contentList.data( 'layout' );
                const showThumbnails = contentList.data( 'show-thumbnails' );
                const showReadTime = contentList.data( 'show-readtime' );
                const showExcerpts = contentList.data( 'show-excerpts' );
                const showContentTypeTags = contentList.data( 'show-content-type-tags' );
                
                // Get page number that is clicked.
                const pageClicked = jQuery( this ).data( 'page-number' );
    
                // Create json for api request.
                const _json = {
                    postType,
                    postId,
                    maxPages,
                    perPage,
                    categories,
                    newsTags,
                    layout,
                    showThumbnails,
                    showReadTime,
                    showExcerpts,
                    showContentTypeTags,
                    pageClicked
                }
                
                // Send api request.
                jQuery.get(
                    restEndpoint.endpoint,
                    _json,
                    function( data ){ 
                        updateBlockData( data, contentList, pageClicked );
                        updatePagination( data, parentNav );
                    },
                    'json' 
                )         
            });
        });
    }
});
;
