// Simple child iframe resizer // Include this on the page that will be embedded in an iframe (function () { if (window.parent === window) { return; } var lastHeight = 0; var lastWidth = 0; var baseFormHeight = 0; function sendSize() { var body = document.body; if (!body) return; var form = document.querySelector('form'); // Reset min-height to get natural form height if (form) { form.style.minHeight = ''; } // Store the natural form height (without dropdown adjustment) var formRect = form.getBoundingClientRect(); baseFormHeight = formRect.height; // Check if dropdown is open var openSelect = document.querySelector('.custom-select.open'); if (openSelect) { var optionsList = openSelect.querySelector('.custom-select__options'); if (optionsList) { var optionsRect = optionsList.getBoundingClientRect(); // Check if dropdown extends past form bottom if (optionsRect.bottom > formRect.bottom) { var extraHeight = optionsRect.bottom - formRect.bottom + 10; form.style.minHeight = (baseFormHeight + extraHeight) + 'px'; } } } // Get final height after any adjustments var height = Math.ceil(body.scrollHeight); var width = Math.max(body.scrollWidth, body.offsetWidth); if (Math.abs(height - lastHeight) < 5 && width === lastWidth) { return; } lastHeight = height; lastWidth = width; window.parent.postMessage({ type: "midaxo-resize", height: height, width: width, }, "*"); } function setupDropdownListeners() { var triggers = document.querySelectorAll('.custom-select__selected'); if (triggers.length === 0) { setTimeout(setupDropdownListeners, 100); return; } triggers.forEach(function(el) { el.addEventListener('click', function() { setTimeout(sendSize, 20); }); }); document.querySelectorAll('.custom-select__option').forEach(function(el) { el.addEventListener('click', function() { setTimeout(sendSize, 20); }); }); document.addEventListener('click', function(e) { if (!e.target.closest('.custom-select')) { setTimeout(sendSize, 20); } }); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", function() { sendSize(); setTimeout(setupDropdownListeners, 200); }); } else { sendSize(); setTimeout(setupDropdownListeners, 200); } window.addEventListener("load", function () { setTimeout(sendSize, 100); setTimeout(setupDropdownListeners, 300); }); var lastWindowWidth = window.innerWidth; window.addEventListener("resize", function () { var currentWidth = window.innerWidth; if (currentWidth !== lastWindowWidth) { lastWindowWidth = currentWidth; sendSize(); } }); window.triggerResize = sendSize; })();