(window.WPCodeCSSLivePreview||function(e,t){const n={previewStyle:null,adminOrigin:null,previewParams:null,init:function(){"undefined"!=typeof wpcodePreviewFrame&&(n.adminOrigin=new URL(wpcodePreviewFrame.adminUrl).origin,n.previewParams={wpcode_preview:"1",snippet_id:String(wpcodePreviewFrame.snippetId)},n.inject_css(),n.listen_for_updates(),n.ensure_preview_navigation(),n.send_ready_message())},inject_css:function(){const i="wpcode-snippet-"+(wpcodePreviewFrame.codeType||"css")+"-"+String(wpcodePreviewFrame.snippetId);if(n.previewStyle=e.getElementById(i),t.parent&&t.parent!==t)try{t.parent.postMessage({action:n.previewStyle?"cssFound":"cssNotFound",snippetId:String(wpcodePreviewFrame.snippetId)},n.adminOrigin)}catch(e){}},listen_for_updates:function(){t.addEventListener("message",function(e){if(e.origin!==n.adminOrigin)return;const t=e.data;"updateCSS"===t.action&&void 0!==t.css&&n.previewStyle&&(n.previewStyle.textContent=t.css)})},ensure_preview_navigation:function(){const i=function(e){try{const i=new URL(e,t.location.href);return i.origin!==t.location.origin?e:(i.searchParams.set("wpcode_preview",n.previewParams.wpcode_preview),i.searchParams.set("snippet_id",n.previewParams.snippet_id),i.toString())}catch(t){return e}};!function(){const t=e.getElementsByTagName("a"),r=t.length;for(let e=0;e<r;e++)n.rewriteLinkHref(t[e],i);const o=e.getElementsByTagName("form"),a=o.length;for(let e=0;e<a;e++)n.rewriteForm(o[e],i,n.previewParams.snippet_id)}(),e.addEventListener("click",function(t){if(t.defaultPrevented||0!==t.button||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return;let n=t.target;for(;n&&n!==e.body;){if(n.tagName&&"a"===n.tagName.toLowerCase()){const e=n.getAttribute("href");e&&0!==e.indexOf("#")&&""!==e.trim()&&n.setAttribute("href",i(e));break}n=n.parentNode}},!0),new MutationObserver(function(e){const t=e.length;for(let r=0;r<t;r++){const t=e[r].addedNodes,o=t.length;for(let e=0;e<o;e++){const r=t[e];if(1!==r.nodeType)continue;r.tagName&&("a"===r.tagName.toLowerCase()&&n.rewriteLinkHref(r,i),"form"===r.tagName.toLowerCase()&&n.rewriteForm(r,i,n.previewParams.snippet_id));const o=r.querySelectorAll?r.querySelectorAll("a[href]"):[],a=o.length;for(let e=0;e<a;e++)n.rewriteLinkHref(o[e],i);const s=r.querySelectorAll?r.querySelectorAll("form"):[],p=s.length;for(let e=0;e<p;e++)n.rewriteForm(s[e],i,n.previewParams.snippet_id)}}}).observe(e.documentElement||e.body,{childList:!0,subtree:!0})},send_ready_message:function(){t.parent!==t&&t.parent.postMessage({action:"previewReady",snippetId:wpcodePreviewFrame.snippetId},n.adminOrigin)},rewriteLinkHref:function(e,t){const n=e.getAttribute("href");if(e.hasAttribute("href")&&n&&""!==n.trim()){const i=t(n);i!==n&&e.setAttribute("href",i)}},rewriteForm:function(n,i,r){const o=(n.getAttribute("method")||"GET").toUpperCase(),a=n.getAttribute("action")||t.location.href;if("GET"===o){const e=i(a);e!==a&&n.setAttribute("action",e)}else{if(!n.querySelector('input[name="wpcode_preview"]')){const t=e.createElement("input");t.type="hidden",t.name="wpcode_preview",t.value="1",n.appendChild(t)}if(!n.querySelector('input[name="snippet_id"]')){const t=e.createElement("input");t.type="hidden",t.name="snippet_id",t.value=r,n.appendChild(t)}}}};return n}(document,window,jQuery)).init();