diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index e6ae0927a..7052d786f 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -46,7 +46,7 @@ function ScrollToElement(attributeName, attributeValue) { } else if (attributeName === 'id') { targetEl = document.getElementById(attributeValue); } else { - console.log('Error: unknown attribute name provided.'); + console.error('Error: unknown attribute name provided.'); return; // Exit the function if an invalid attributeName is provided } @@ -78,6 +78,50 @@ function makeVisible(el) { el.style.visibility = "visible"; } +/** + * Toggles expand_more / expand_more svgs in buttons or anchors + * @param {Element} element - DOM element + */ +function toggleCaret(element) { + // Get a reference to the use element inside the button + const useElement = element.querySelector('use'); + // Check if the span element text is 'Hide' + if (useElement.getAttribute('xlink:href') === '/public/img/sprite.svg#expand_more') { + // Update the xlink:href attribute to expand_more + useElement.setAttribute('xlink:href', '/public/img/sprite.svg#expand_less'); + } else { + // Update the xlink:href attribute to expand_less + useElement.setAttribute('xlink:href', '/public/img/sprite.svg#expand_more'); + } +} + +/** + * Helper function that scrolls to an element + * @param {string} attributeName - The string "class" or "id" + * @param {string} attributeValue - The class or id name + */ +function ScrollToElement(attributeName, attributeValue) { + let targetEl = null; + + if (attributeName === 'class') { + targetEl = document.getElementsByClassName(attributeValue)[0]; + } else if (attributeName === 'id') { + targetEl = document.getElementById(attributeValue); + } else { + console.error('Error: unknown attribute name provided.'); + return; // Exit the function if an invalid attributeName is provided + } + + if (targetEl) { + const rect = targetEl.getBoundingClientRect(); + const scrollTop = window.scrollY || document.documentElement.scrollTop; + window.scrollTo({ + top: rect.top + scrollTop, + behavior: 'smooth' // Optional: for smooth scrolling + }); + } +} + /** Creates and returns a live region element. */ function createLiveRegion(id) { const liveRegion = document.createElement("div"); @@ -927,7 +971,7 @@ function unloadModals() { * @param {string} itemName - The name displayed in the counter * @param {string} paginationSelector - CSS selector for the pagination container. * @param {string} counterSelector - CSS selector for the pagination counter. - * @param {string} headerAnchor - CSS selector for the header element to anchor the links to. + * @param {string} linkAnchor - CSS selector for the header element to anchor the links to. * @param {Function} loadPageFunction - Function to call when a page link is clicked. * @param {number} currentPage - The current page number (starting with 1). * @param {number} numPages - The total number of pages. @@ -936,7 +980,7 @@ function unloadModals() { * @param {number} totalItems - The total number of items. * @param {string} searchTerm - The search term */ -function updatePagination(itemName, paginationSelector, counterSelector, headerAnchor, loadPageFunction, currentPage, numPages, hasPrevious, hasNext, totalItems, searchTerm) { +function updatePagination(itemName, paginationSelector, counterSelector, linkAnchor, loadPageFunction, currentPage, numPages, hasPrevious, hasNext, totalItems, searchTerm) { const paginationContainer = document.querySelector(paginationSelector); const paginationCounter = document.querySelector(counterSelector); const paginationButtons = document.querySelector(`${paginationSelector} .usa-pagination__list`); @@ -955,7 +999,7 @@ function updatePagination(itemName, paginationSelector, counterSelector, headerA const prevPageItem = document.createElement('li'); prevPageItem.className = 'usa-pagination__item usa-pagination__arrow'; prevPageItem.innerHTML = ` - + @@ -974,7 +1018,7 @@ function updatePagination(itemName, paginationSelector, counterSelector, headerA const pageItem = document.createElement('li'); pageItem.className = 'usa-pagination__item usa-pagination__page-no'; pageItem.innerHTML = ` - ${page} + ${page} `; if (page === currentPage) { pageItem.querySelector('a').classList.add('usa-current'); @@ -1020,7 +1064,7 @@ function updatePagination(itemName, paginationSelector, counterSelector, headerA const nextPageItem = document.createElement('li'); nextPageItem.className = 'usa-pagination__item usa-pagination__arrow'; nextPageItem.innerHTML = ` - + Next
{% if portfolio is None %}
@@ -11,10 +11,10 @@
-