UNPKG

nextjs-jotform-embed

Version:

Embed Jotform iframe to your NextJS or React application easily

2 lines (1 loc) 3.3 kB
import e,{memo as t,useRef as n,useEffect as r}from"react";function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){l(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function l(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a={border:"none",width:"100%"},s=t((function(t){var o=t.src,l=t.className,s=t.styles,u=t.allowScrolling,m=void 0!==u&&u,f=n(null);r((function(){return global.addEventListener?global.addEventListener("message",d,!1):global.attachEvent&&global.attachEvent("onmessage",d),function(){global.removeEventListener?global.removeEventListener("message",d,!1):global.detachEvent&&global.detachEvent("onmessage",d)}}),[]);var d=function(e){if("object"!==c(e.data)){var t=e.data.split(":"),n=f.current;if(n){switch(t[0]){case"scrollIntoView":n.scrollIntoView();break;case"setHeight":n.style.height=t[1]+"px",!isNaN(t[1])&&parseInt(n.style.minHeight)>parseInt(t[1])&&(n.style.minHeight=t[1]+"px");break;case"collapseErrorPage":n.clientHeight>window.innerHeight&&(n.style.height=window.innerHeight+"px");break;case"reloadPage":window.location.reload();break;case"loadScript":if(!function(e,t){var n=document.createElement("a");n.href=e;var r=n.hostname,o=!1;if(void 0!==r)return t.forEach((function(e){r.slice(-1*e.length-1)!==".".concat(e)&&r!==e||(o=!0)})),o}(e.origin,["jotform.com","jotform.pro"]))break;var r=t[1];t.length>3&&(r=t[1]+":"+t[2]);var o=document.createElement("script");o.src=r,o.type="text/javascript",document.body.appendChild(o);break;case"exitFullscreen":window.document.exitFullscreen?window.document.exitFullscreen():window.document.mozCancelFullScreen||window.document.mozCancelFullscreen?window.document.mozCancelFullScreen():window.document.webkitExitFullscreen?window.document.webkitExitFullscreen():window.document.msExitFullscreen&&window.document.msExitFullscreen()}if(e.origin.indexOf("jotform")>-1&&"contentWindow"in n&&"postMessage"in n.contentWindow){var i={docurl:encodeURIComponent(document.URL),referrer:encodeURIComponent(document.referrer)};n.contentWindow.postMessage(JSON.stringify({type:"urls",value:i}),"*")}}}};return e.createElement("iframe",{ref:f,className:l,src:o,style:i(i({},a),s),scrolling:m?"yes":"no"})}));export{s as JotformEmbed};