[cmplz-terms-conditions type=”terms-conditions”]
document.addEventListener('DOMContentLoaded', function () {
const url = new URL(window.location.href);
url.searchParams.delete('status');
url.searchParams.delete('user_id');
window.history.replaceState(
{},
document.title,
url.pathname + url.search + url.hash
);
});
document.addEventListener('DOMContentLoaded', function () {
function formatPhoneNumbers() {
document.querySelectorAll('.format-phone').forEach(function (element) {
// JetEngine puts the actual field value inside this element
const valueElement =
element.querySelector('.jet-listing-dynamic-field__content') || element;
// Don't format the same value repeatedly
if (valueElement.dataset.phoneFormatted === 'true') {
return;
}
let digits = valueElement.textContent.replace(/\D/g, '');
// Remove leading US country code
if (digits.length === 11 && digits.charAt(0) === '1') {
digits = digits.substring(1);
}
// Format 10-digit US number
if (digits.length === 10) {
valueElement.textContent =
'(' + digits.substring(0, 3) + ') ' +
digits.substring(3, 6) + '-' +
digits.substring(6);
valueElement.dataset.phoneFormatted = 'true';
}
});
}
// Initial formatting
formatPhoneNumbers();
// Allow JetEngine listings to finish rendering
setTimeout(formatPhoneNumbers, 500);
setTimeout(formatPhoneNumbers, 1500);
setTimeout(formatPhoneNumbers, 3000);
});