formtress-js 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/core.js +1 -1
- package/dist/js/webflow.js +1 -1
- package/package.json +1 -1
package/dist/js/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
async function p(n){const{url:o,data:c,method:i="POST",headers:r={}}=n,t=await fetch(o,{method:i,body:c,headers:{Accept:"application/json",...r}});let e="",s;if((t.headers.get("content-type")||"").includes("application/json"))try{const a=await t.json();e=a.message||"",typeof a.redirect=="string"&&(s=a.redirect)}catch{e=await t.text()}else e=await t.text();return{ok:t.ok,status:t.status,message:e,...s?{redirect:s}:{}}}export{p as submitForm};
|
package/dist/js/webflow.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function p(){document.querySelectorAll('form[action*="app.formtress.com/api/f/"]').forEach(o=>{const l=o.closest(".w-form");if(!l)return;const d=l.querySelector(".w-form-done"),r=l.querySelector(".w-form-fail");if(!d||!r)return;let u=!1;const t=l.querySelector("input.w-button")||o.querySelector('button:not([type="button"])')||o.querySelector('input[type="submit"]'),f=t instanceof HTMLInputElement,e=o.querySelector("[data-ft-loading-text]"),i=r.querySelector("[data-ft-error]")||r.firstChild;function m(){return t?e?e.textContent||"":f?t.value:t.textContent||"":""}function c(s){t&&(e?e.textContent=s:f&&(t.value=s))}function w(){return e!=null&&e.dataset.ftLoadingText?e.dataset.ftLoadingText:e!=null&&e.dataset.wait?e.dataset.wait:t!=null&&t.dataset.wait?t.dataset.wait:"Please wait..."}o.addEventListener("submit",async function(s){if(s.preventDefault(),s.stopPropagation(),u)return;u=!0,r.style.display="none";const y=m();c(w()),t&&t.setAttribute("disabled","");try{const n=await fetch(o.action,{method:"POST",body:new FormData(o),headers:{Accept:"application/json"}});if(n.ok){o.style.display="none",d.style.display="block";const a=await n.json();a.redirect&&(window.location.href=a.redirect)}else if(n.status===429)console.error("Form submission rate limited:",n.status),i&&(i.textContent="Too many submissions. Please wait a moment and try again."),r.style.display="block";else{const a=await n.text();console.error("Form submission failed:",n.status,a),i&&(i.textContent=a),r.style.display="block"}u=!1,c(y),t&&t.removeAttribute("disabled")}catch(n){console.error("Error submitting form:",n),i&&(i.textContent="An error occurred. Please try again later."),r.style.display="block",c(y),t&&t.removeAttribute("disabled"),u=!1}})})}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",p):p());
|