(function () { var currentScript = document.currentScript || (function () { var scripts = document.getElementsByTagName('script'); return scripts[scripts.length - 1]; })(); var organizationId = currentScript.getAttribute('data-organization-id'); if (!organizationId) { return; } var iframe = document.createElement('iframe'); iframe.id = 'meadow-intake-embed'; iframe.scrolling = 'no'; iframe.seamless = 'seamless'; iframe.src = '//intake-staging.getmeadow.com/intake/' + organizationId; iframe.style.border = 'none'; iframe.style.height = '708px'; iframe.style.overflow = 'hidden'; iframe.style.width = '100%'; currentScript.parentNode.appendChild(iframe); if (window.addEventListener) { var positionForElement = function (element) { var xPosition = 0; var yPosition = 0; while (element) { xPosition += element.offsetLeft; yPosition += element.offsetTop; element = element.offsetParent; } return { x: xPosition, y: yPosition }; }; var objectForMessage = function (message) { var messageArray = message.split('?'); var messageObject = {}; for (var i = 0; i < messageArray.length; i += 2) { messageObject[messageArray[i]] = messageArray[i + 1]; } return messageObject; }; window.addEventListener('message', function (event) { if (event.origin.indexOf('intake-staging.getmeadow.com') === -1) { return; } if (event.data.substring(0, 30) === 'meadow-intake://show-signature') { var signatureUrl = event.data.replace('meadow-intake://show-signature/', ''); var source = '//intake-staging.getmeadow.com/signature.html?signatureUrl=' + signatureUrl; var iframePosition = positionForElement(iframe); var signatureIframe = document.createElement('iframe'); signatureIframe.id = 'meadow-intake-signature'; signatureIframe.scrolling = 'yes'; signatureIframe.src = source; signatureIframe.style.border = 'none'; signatureIframe.style.overflow = 'hidden'; signatureIframe.style.position = 'absolute'; signatureIframe.style.top = iframePosition.y + 'px'; signatureIframe.style.right = '0'; signatureIframe.style.bottom = '0'; signatureIframe.style.left = '0'; signatureIframe.style.height = '100%'; signatureIframe.style.width = '100%'; signatureIframe.style.zIndex = '99999'; document.body.appendChild(signatureIframe); window.scrollTo(0, iframePosition.y); } else if (event.data.substring(0, 34) === 'meadow-intake://signature-success/') { var signatureId = event.data.replace('meadow-intake://signature-success/', ''); var payload = JSON.stringify({ organizationId: organizationId, signatureId: signatureId }); iframe.contentWindow.postMessage('meadow-intake://signature-success/' + payload, '*'); document.body.removeChild(document.getElementById('meadow-intake-signature')); } else if (event.data === 'meadow-intake://signature-failure') { document.body.removeChild(document.getElementById('meadow-intake-signature')); iframe.contentWindow.postMessage('meadow-intake://signature-failure/' + organizationId, '*'); } else if (event.data.substring(0, 16) === 'meadow-intake://') { var messageData = objectForMessage(event.data.replace('meadow-intake://', '')); var meadowFrame = document.getElementById('meadow-intake-embed'); if (messageData.height && meadowFrame) { meadowFrame.style.height = messageData.height; } } }); } else { iframe.scrolling = 'yes'; } })();