mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-20 17:56:11 +02:00
trace down the modal unload error and fix it in uswds
This commit is contained in:
parent
0b4cdf7a69
commit
ff3d18eeae
2 changed files with 42 additions and 42 deletions
|
@ -33,6 +33,33 @@ const showElement = (element) => {
|
||||||
element.classList.remove('display-none');
|
element.classList.remove('display-none');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.log('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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Makes an element invisible. */
|
/** Makes an element invisible. */
|
||||||
function makeHidden(el) {
|
function makeHidden(el) {
|
||||||
el.style.position = "absolute";
|
el.style.position = "absolute";
|
||||||
|
@ -895,33 +922,6 @@ function unloadModals() {
|
||||||
window.modal.off();
|
window.modal.off();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.log('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
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generalized function to update pagination for a list.
|
* Generalized function to update pagination for a list.
|
||||||
* @param {string} itemName - The name displayed in the counter
|
* @param {string} itemName - The name displayed in the counter
|
||||||
|
@ -1508,12 +1508,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
const submitButton = modal.querySelector('.usa-modal__submit');
|
const submitButton = modal.querySelector('.usa-modal__submit');
|
||||||
const closeButton = modal.querySelector('.usa-modal__close');
|
const closeButton = modal.querySelector('.usa-modal__close');
|
||||||
|
|
||||||
// Clone the submit button to remove all existing event listeners
|
|
||||||
const newSubmitButton = submitButton.cloneNode(true);
|
|
||||||
submitButton.parentNode.replaceChild(newSubmitButton, submitButton);
|
|
||||||
|
|
||||||
newSubmitButton.addEventListener('click', function() {
|
submitButton.addEventListener('click', function() {
|
||||||
pk = newSubmitButton.getAttribute('data-pk');
|
pk = submitButton.getAttribute('data-pk');
|
||||||
// Close the modal to remove the USWDS UI local classes
|
// Close the modal to remove the USWDS UI local classes
|
||||||
closeButton.click();
|
closeButton.click();
|
||||||
// If we're deleting the last item on a page that is not page 1, we'll need to refresh the display to the previous page
|
// If we're deleting the last item on a page that is not page 1, we'll need to refresh the display to the previous page
|
||||||
|
|
|
@ -5311,14 +5311,17 @@ const cleanUpModal = baseComponent => {
|
||||||
const modalID = modalWrapper.getAttribute("id");
|
const modalID = modalWrapper.getAttribute("id");
|
||||||
const originalLocationPlaceHolder = document.querySelector(`[data-placeholder-for="${modalID}"]`);
|
const originalLocationPlaceHolder = document.querySelector(`[data-placeholder-for="${modalID}"]`);
|
||||||
if (originalLocationPlaceHolder) {
|
if (originalLocationPlaceHolder) {
|
||||||
for (let attributeIndex = 0; attributeIndex < originalLocationPlaceHolder.attributes.length; attributeIndex += 1) {
|
// DOTGOV
|
||||||
const attribute = originalLocationPlaceHolder.attributes[attributeIndex];
|
// Why is this line here? It seems to be recreating the original placeholder and then adding a
|
||||||
if (attribute.name.startsWith('data-original-')) {
|
// copy of it after that first placeholder, which is netralizing our call of off()
|
||||||
// data-original- is 14 long
|
// for (let attributeIndex = 0; attributeIndex < originalLocationPlaceHolder.attributes.length; attributeIndex += 1) {
|
||||||
modalContent.setAttribute(attribute.name.substr(14), attribute.value);
|
// const attribute = originalLocationPlaceHolder.attributes[attributeIndex];
|
||||||
}
|
// if (attribute.name.startsWith('data-original-')) {
|
||||||
}
|
// // data-original- is 14 long
|
||||||
originalLocationPlaceHolder.after(modalContent);
|
// modalContent.setAttribute(attribute.name.substr(14), attribute.value);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//originalLocationPlaceHolder.after(modalContent);
|
||||||
originalLocationPlaceHolder.parentElement.removeChild(originalLocationPlaceHolder);
|
originalLocationPlaceHolder.parentElement.removeChild(originalLocationPlaceHolder);
|
||||||
}
|
}
|
||||||
modalWrapper.parentElement.removeChild(modalWrapper);
|
modalWrapper.parentElement.removeChild(modalWrapper);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue