(function (settings) { var appendQuery = function appendQuery(url, query) { if (0 === query.length) { return url; } if ('?' == query.charAt(0)) { query = query.substring(1); } var separator = (-1 !== url.indexOf('?')) ? '&' : '?'; return url + separator + query; }; var shouldLoadThankYouPage = function() { var queryParams = window.location.search.substr(1).split('&').reduce(function (q, query) { var chunks = query.split('='); var key = chunks[0]; var value = chunks[1]; return (q[key] = value, q); }, {}); return queryParams['nm-embed-show-thank-you'] === '1'; }; var firstScriptElement = document.getElementsByTagName('script')[0]; if (settings.share_progress_js_url) { var scriptElementSP = document.createElement('script'); scriptElementSP.async = 1; scriptElementSP.src = settings.share_progress_js_url; firstScriptElement.parentNode.insertBefore(scriptElementSP,firstScriptElement); } if (settings.pym_lib_url) { var scriptElement = document.createElement('script'); scriptElement.async = 1; scriptElement.src = settings.pym_lib_url; firstScriptElement.parentNode.insertBefore(scriptElement,firstScriptElement); scriptElement.onload = function () { if (settings.div_id && settings.iframe_url) { var url = appendQuery(settings.iframe_url, document.location.search); if (shouldLoadThankYouPage() && settings.thank_you_url) { url = appendQuery(settings.thank_you_url, document.location.search); } var pymParent = new pym.Parent(settings.div_id, url, {}); // Allow child to learn about parent URL, for cases where iframe content has navigated away from original URL with parentUrl parameter. pymParent.onMessage('getParentUrl', function() { this.sendMessage('parentUrl', encodeURIComponent(window.location.href)); }); // pym.js sets the iframe height via the HTML "height" attribute, which // can get overridden by (unrelated) CSS rules. So, in addition, we also // set the CSS "height" property directly on the iframe, which in turn // overrides any CSS applied via rules. pymParent.onMessage('height', function(message) { var height = parseInt(message); if ('style' in this.iframe) { if ('height' in this.iframe.style) { this.iframe.style.height = height + 'px'; } } }); } }; } if (settings.font_url) { var head = document.head || document.getElementsByTagName('head')[0], link = document.createElement('link'); link.setAttribute('rel', 'stylesheet'); link.setAttribute('type', 'text/css'); link.setAttribute('href', settings.font_url); head.appendChild(link); } // Do not append anything after the closing parenthesis! })({ "pym_lib_url": "//engage.newmode.net/profiles/newmode/libraries/pym/pym.js", "share_progress_js_url": "//c.shpg.org/392/sp.js", "div_id": "newmode-embed-4348-4757", "iframe_url": "//engage.newmode.net/nm-letter/4348/4757", "font_url": "", "thank_you_url": "https://engage.newmode.net/node/4757/done" });