/*]*)>/gi, (match, attrs) => { attrs = attrs.replace(/\s*type\s*=\s*(['"]).*?\1/i, ''); return ``; } ); const onIframeLoad = new Promise(resolve => { iframe.onload = resolve; }); const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; iframeDoc.open(); iframeDoc.write(htmlString); iframeDoc.close(); onIframeLoad.then(() => { const newHtml = iframeDoc.documentElement; if ((typeof scrollPositionX !== "undefined") && (typeof scrollPositionY !== "undefined")) { newHtml.style.visibility = 'hidden'; onImagesDecoded(() => { window.scrollTo(scrollPositionX, scrollPositionY); newHtml.style.visibility = ''; }); } document.documentElement.replaceWith(newHtml); iframe.remove(); showBody(); runScripts(); }); } function onImagesDecoded(callback) { const images = Array.from(document.images); if (images.length === 0) { callback(); return; } let remaining = images.length; const done = () => { remaining--; if (remaining <= 0) callback(); }; images.forEach(img => { if (img.complete) { img.decode?.().then(done).catch(done); } else { img.addEventListener('load', () => { img.decode?.().then(done).catch(done); }, { once: true }); img.addEventListener('error', done, { once: true }); } }); } function runScripts () { // Get the scripts var scripts = document.body.getElementsByTagName("script"); // Run them in sequence (remember NodeLists are live) continueLoading(); function continueLoading() { var script, newscript; // While we have a script to load... while (scripts.length) { // Get it and remove it from the DOM script = scripts[0]; script.parentNode.removeChild(script); // Skip the accordionInitializer script, it only needs to execute at the initial load of the dyn-poll-page if(script.getAttribute("id") === "accordionInitializer") { continue; } // Create a replacement for it newscript = document.createElement("script"); // External? if (script.src) { // Yes, we'll have to wait until it's loaded before continuing newscript.onerror = continueLoadingOnError; newscript.onload = continueLoadingOnLoad; newscript.onreadystatechange = continueLoadingOnReady; newscript.src = script.src; } else { // No, we can do it right away newscript.text = script.text; } // Start the script document.documentElement.appendChild(newscript); // If it's external, wait for callback if (script.src) { return; } } // All scripts loaded newscript = undefined; // Callback on most browsers when a script is loaded function continueLoadingOnLoad() { // Defend against duplicate calls if (this === newscript) { continueLoading(); } } // Callback on most browsers when a script fails to load function continueLoadingOnError() { // Defend against duplicate calls if (this === newscript) { continueLoading(); } } // Callback on IE when a script's loading status changes function continueLoadingOnReady() { // Defend against duplicate calls and check whether the // script is complete (complete = loaded or error) if (this === newscript && this.readyState === "complete") { continueLoading(); } } } } function poll (pollInterval) { if(!requestPending) { pollTriggered = false; if (document.visibilityState === "hidden") { skippedPollWhenVisibilityStateHidden = true; } else { var form = document.querySelector("form") var action = form.getAttribute("action"); var xhr = new XMLHttpRequest(); xhr.addEventListener("loadstart", function () { document.getElementById("mainFormSubmitHidden") .addEventListener("click", function (e) { e.preventDefault(); }); document.getElementById("finish").disabled = true; }); xhr.open("POST", action); xhr.send(new FormData(form)); xhr.onreadystatechange = function () { if (this.readyState === XMLHttpRequest.DONE) { if (this.status === 200) { if ((typeof scrollPositionX !== "undefined") && (typeof scrollPositionY !== "undefined")) { scrollPositionX = window.scrollX; scrollPositionY = window.scrollY; } replaceHTML(this.responseText); } else { triggerNextPoll(pollInterval); } } }; xhr.onerror = function () { triggerNextPoll(pollInterval); }; } } } function triggerNextPoll (pollInterval) { if (!pollTriggered) { setTimeout(function () { poll(pollInterval); }, pollInterval); pollTriggered = true; } } document.addEventListener("visibilitychange", () => { if (document.visibilityState === "visible") { if (skippedPollWhenVisibilityStateHidden) { skippedPollWhenVisibilityStateHidden = false; poll(pollInterval); } } }); // initial trigger for the polling after page is loaded. if (window.FormData === undefined) { // we are on an old browser. E.g. IE9 so we poll the traditional way. setTimeout(function () { document.getElementById("mainFormSubmitHidden").click(); }, pollInterval); } else { // we are on a new browser so we poll the new way. triggerNextPoll(pollInterval); } /*]]>*/θΈγωλτ