-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopeniframe.min.js
More file actions
1 lines (1 loc) · 1.68 KB
/
openiframe.min.js
File metadata and controls
1 lines (1 loc) · 1.68 KB
1
class OpenIframe{constructor(e){this.container=e.container,this.iframeWidth=parseFloat(e.width)||800,this.iframeHeight=parseFloat(e.height)||600,this.append=e.append||!1,this.src=e.src||"#",this.proxyUrl="https://serene-hamlet-82201.herokuapp.com/",this.runPolyfills(),this.validationContainer(()=>{this.createIframeElement()})}runPolyfills(){var e;(e=[Element.prototype,Document.prototype,DocumentFragment.prototype]).forEach(e=>{e.hasOwnProperty("append")||Object.defineProperty(e,"append",{configurable:!0,enumerable:!0,writable:!0,value:function(){const e=Array.prototype.slice.call(arguments),t=document.createDocumentFragment();e.forEach(e=>{const r=e instanceof Node;t.appendChild(r?e:document.createTextNode(String(e)))}),this.appendChild(t)}})}),e.forEach(e=>{e.hasOwnProperty("prepend")||Object.defineProperty(e,"prepend",{configurable:!0,enumerable:!0,writable:!0,value:function(){const e=Array.prototype.slice.call(arguments),t=document.createDocumentFragment();e.forEach(e=>{const r=e instanceof Node;t.appendChild(r?e:document.createTextNode(String(e)))}),this.insertBefore(t,this.firstChild)}})})}validationContainer(e){let t=!0;if("string"==typeof this.container)try{null===document.querySelector(this.container)?(t=!1,console.error("OpenIframe: is not a valid selector or element not found")):this.container=document.querySelector(this.container)}catch(e){t=!1,console.error("OpenIframe: is not a valid selector.")}!this.container instanceof HTMLElement&&(t=!1),t&&e()}createIframeElement(){const e=document.createElement("iframe");return e.src=`${this.proxyUrl}?proxyHost=${this.src}`,e.width=this.iframeWidth,e.height=this.iframeHeight,this.append?this.container.append(e):this.container.prepend(e)}}