';
console.log('Home WPForms content added');
}
if (communityFormContainer) {
communityFormContainer.innerHTML = ' ';
console.log('Community WPForms content added');
}
// Get popup elements
var homePopup = document.getElementById('hollows-popup-overlay');
var communityPopup = document.getElementById('hollows-community-popup-overlay');
var homeCloseBtn = document.getElementById('hollows-popup-close');
var communityCloseBtn = document.getElementById('hollows-community-popup-close');
if (!homePopup || !communityPopup) {
console.error('Popup elements not found');
return;
}
// Open popup functions
function openHomePopup() {
console.log('Opening home popup...');
homePopup.classList.add('active');
document.body.style.overflow = 'hidden';
// Populate house address after a brief delay (only for home popup)
setTimeout(function() {
populateHouseAddress();
}, 200);
}
function openCommunityPopup() {
console.log('Opening community popup...');
communityPopup.classList.add('active');
document.body.style.overflow = 'hidden';
}
// Close popup functions
function closeHomePopup() {
console.log('Closing home popup...');
homePopup.classList.remove('active');
document.body.style.overflow = '';
}
function closeCommunityPopup() {
console.log('Closing community popup...');
communityPopup.classList.remove('active');
document.body.style.overflow = '';
}
// Function to get house address
function getHouseAddress() {
var address = '';
// Method 1: Look for h1 tag
var h1 = document.querySelector('h1');
if (h1) {
address = h1.textContent.trim();
}
// Method 2: Extract from URL
if (!address) {
var urlPath = window.location.pathname;
var matches = urlPath.match(/\/([0-9]+[^\/]*)/);
if (matches && matches[1]) {
address = matches[1].replace(/-/g, ' ').replace(/\//g, '');
// Capitalize each word
address = address.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
}
console.log('Found address:', address);
return address;
}
// Function to populate house address field
function populateHouseAddress() {
var address = getHouseAddress();
console.log('Attempting to populate address:', address);
if (address) {
// Wait a bit for WPForms to fully load
setTimeout(function() {
// Target the specific field ID 6 for House Address
var addressField = document.querySelector('#wpforms-7741-field_6') ||
document.querySelector('input[name="wpforms[fields][6]"]');
if (addressField) {
addressField.value = address;
console.log('Address populated successfully:', address);
// Trigger change events to ensure WPForms recognizes the value
addressField.dispatchEvent(new Event('change', { bubbles: true }));
addressField.dispatchEvent(new Event('input', { bubbles: true }));
} else {
console.log('Address field not found. Available form fields:');
// Debug: log all available form fields
var allFields = document.querySelectorAll('#wpforms-7741-field_6, input[name*="wpforms"]');
allFields.forEach(function(field) {
console.log('Field found:', field.name || field.id, field);
});
}
}, 300);
} else {
console.log('No address found to populate');
}
}
// Event listener for clicks
document.addEventListener('click', function(e) {
console.log('Click detected on:', e.target);
// Check for COMMUNITY INQUIRY triggers FIRST (more specific)
var communityTarget = e.target.closest('a[href="#inquirecommunity"]') ||
e.target.closest('a[href*="inquirecommunity"]');
// Check for HOME INQUIRY triggers (only if not community)
var homeTarget = null;
if (!communityTarget) {
homeTarget = e.target.closest('a[href="#inquirenow"]') ||
e.target.closest('a[href*="inquirenow"]');
}
// Also check by button text (only if no URL matches found)
var buttonText = e.target.textContent || '';
if (!homeTarget && !communityTarget) {
if (buttonText.toLowerCase().includes('inquire about our community')) {
communityTarget = e.target;
} else if (buttonText.toLowerCase().includes('inquire about this home') ||
buttonText.toLowerCase().includes('request information')) {
homeTarget = e.target;
}
}
// Debug logging
console.log('Community target:', communityTarget);
console.log('Home target:', homeTarget);
console.log('Button text:', buttonText);
if (communityTarget) {
console.log('Community target found, opening community popup...');
e.preventDefault();
e.stopPropagation();
openCommunityPopup();
return false;
}
if (homeTarget) {
console.log('Home target found, opening home popup...');
e.preventDefault();
e.stopPropagation();
openHomePopup();
return false;
}
});
// Close popup events
if (homeCloseBtn) {
homeCloseBtn.addEventListener('click', function(e) {
e.preventDefault();
closeHomePopup();
});
}
if (communityCloseBtn) {
communityCloseBtn.addEventListener('click', function(e) {
e.preventDefault();
closeCommunityPopup();
});
}
homePopup.addEventListener('click', function(e) {
if (e.target === homePopup) {
closeHomePopup();
}
});
communityPopup.addEventListener('click', function(e) {
if (e.target === communityPopup) {
closeCommunityPopup();
}
});
// Escape key to close
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
if (homePopup.classList.contains('active')) {
closeHomePopup();
}
if (communityPopup.classList.contains('active')) {
closeCommunityPopup();
}
}
});
console.log('Hollows Popup initialized successfully');
}
// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initHollowsPopup);
} else {
initHollowsPopup();
}
})();