Files
hub-insurance/wp-content/plugins/generateblocks-pro/dist/form-iframe-context.js
T
2026-07-02 15:54:39 -06:00

1 line
3.0 KiB
JavaScript

(()=>{"use strict";const t=window.wp.i18n;!function(){const e=new URLSearchParams(window.location.search);if("1"!==e.get("gb_form_context"))return;let n=!1,o=!1,r=null===e.get("post")&&window.location.pathname.includes("post-new.php");const i=window.location.origin;function s(t,e={}){try{window.parent.postMessage({type:`gb_${t}`,source:"form_iframe",timestamp:Date.now(),...e},i)}catch(t){}}function a(t,n=null){if(!t)return!0;if("_blank"===n?.target)return!0;if(t.startsWith("#"))return!0;if(t.startsWith("?")||t.includes("admin-ajax.php")||t.includes("/wp-json/"))return!0;if(t.includes("async-upload.php")||t.includes("media-upload.php"))return!0;const o=e.get("post");if(o&&t.includes(`post=${o}`))return!0;if(n){const t=n.textContent?.toLowerCase()||"",e=n.className?.toLowerCase()||"";if(["save","update","publish"].some((n=>t.includes(n)||e.includes(n))))return!0}return!1}function u(e){const o=n?(0,t.__)("You have unsaved changes. This will leave the form editor.","generateblocks-pro"):(0,t.__)("This will leave the form editor.","generateblocks-pro"),r=(0,t.__)("Would you like to open this page in a new tab instead?","generateblocks-pro");window.confirm(`${o}\n\n${r}`)&&window.open(e,"_blank")}function d(t){const e=t.target.closest("a[href]");if(!e)return;const n=e.getAttribute("href");n&&(a(n,e)||(t.preventDefault(),t.stopPropagation(),u(n)))}function c(t){const e=t.target?.action||window.location.href;a(e,t.submitter)||(t.preventDefault(),u(e))}function l(){if(o)return;document.addEventListener("click",d,!0),document.addEventListener("submit",c,!0),window.addEventListener("beforeunload",(e=>{if(!n)return;const o=(0,t.__)("You have unsaved changes. Are you sure you want to leave?","generateblocks-pro");return e.preventDefault(),e.returnValue=o,o}));const e=function(){if(!window.wp?.data)return null;const{select:t,subscribe:e}=window.wp.data;let o="",i=null,a=!1,u=!1,d=0;return e((()=>{try{const c=t("core/editor"),l=c?.getCurrentPostType?.();if("gblocks_form"!==l)return;const f=Number(c?.getCurrentPostId?.())||0,p=(e=c?.getEditedPostAttribute?.("title"),"string"==typeof e?e:e&&"object"==typeof e?"string"==typeof e.rendered?e.rendered:"string"==typeof e.raw?e.raw:"":""),g=c?.getEditedPostAttribute?.("content")||"",w=c?.getEditedPostAttribute?.("meta")||{},h=c?.getEditedPostAttribute?.("status")||"",m=c?.getEditedPostAttribute?.("modified")||"",v=JSON.stringify({title:p,content:g,meta:w,status:h});if(!a){if(!f)return;return i=v,o=m,u=!!m,d=f,void(a=!0)}if(f&&f!==d)return i=v,o=m,u=!!m,d=f,void(n&&(n=!1,s("unsaved_changes",{hasChanges:!1})));const b=c?.isSavingPost?.(),_=c?.isAutosavingPost?.();if(!u)return void(m&&(o=m,i=v,u=!0));if(!b&&!_&&m&&m!==o)return o=m,i=v,n&&(n=!1,s("unsaved_changes",{hasChanges:!1})),void(f&&(s("form_saved",{formId:f,formTitle:p,formStatus:h,isNew:r}),r=!1));if(b||_)return;const y=v!==i;y!==n&&(n=y,s("unsaved_changes",{hasChanges:y}))}catch(t){}var e}))}();o=!0,window.addEventListener("beforeunload",(()=>{e&&e()}))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",l):l()}()})();