Drupal.behaviors.jacobsGpse = {
    attach: function(context, settings) {
        // Clear gsc results and url upon clicking on 'X'icon.
        document.querySelector('.nav__close-button').addEventListener('click', function() {
            const myClose = document.querySelector('.gsst_a');
            const gscResults = document.querySelector('.gsc-results-wrapper-nooverlay');
            const resultsBox = document.querySelector('.gsc-resultsbox-visible');
            const resultsCount = document.querySelector('.gsc-above-wrapper-area');
            const searchBox = document.querySelector('.gsib_a .gsc-input');
            // Create a URL object from the current location.
            const url = new URL(window.location.href);
            // Set the search string to an empty string.
            url.hash = '';
            // Update the URL in the browser without reloading the page.
            window.history.replaceState({}, document.title, url);
            myClose.style.display = 'none';
            gscResults.classList.remove('gsc-results-wrapper-visible');
            resultsBox.classList.add('gsc-resultsbox-invisible');
            resultsCount.classList.add('gsc-above-wrapper-area-invisible');
            searchBox.value = '';
        });
    }
};