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C7C,MAAMC,GAAG,GAAGlC,QAAQ,CAACmC,aAAa,CAAC,KAAK,CAAC;IACzCD,GAAG,CAACE,SAAS,GAAGH,IAAI;IACpB,OAAOC,GAAG,CAACG,UAAyB;EACxC;EAEQ7B,kBAAkBA,CAAA;IACtBtB,iBAAiB,CAAC0B,GAAG,CAAC,eAAe,CAAC;IAEtC,MAAM0B,GAAG,GAAGlC,MAAa;IACzBkC,GAAG,CAACC,kBAAkB,GAAG,IAAI;IAC7BC,YAAY,CAACF,GAAG,CAAC5B,mBAAmB,CAAC;IAErC,IAAI,CAACG,oBAAoB,CAAC,KAAK,CAAC;EACpC;EAEQ,OAAOD,GAAGA,CAAC6B,GAAW;IAC1BvC,OAAO,CAACU,GAAG,CAAC,eAAe6B,GAAG,EAAE,CAAC;EACrC;;AAGJ,IAAIvD,iBAAiB,EAAE,CAACU,iBAAiB,EAAE,C","sources":["webpack://Bundle_/./Ui/PortalEmbed/parent.ts"],"sourcesContent":["/* Embed the client portal in other sites and workaround browser limitations.\r\n *\r\n * BASIC USAGE: Add the script right after the IFRAME embed. Make sure the IFRAME has id='powerdiary_portal'\r\n *\r\n * \r\n * \r\n *\r\n * ADVANCED OPTIONS:\r\n * Specify settings in the window variable, prefixing them with 'PD_'. Enter these options\r\n * in a before linking the script.\r\n * For example:\r\n * \r\n * \r\n * \r\n *\r\n * */\r\n\r\nclass PortalEmbedParent {\r\n private iframe: HTMLIFrameElement = null;\r\n private defaultSettings: { [id: string]: any } = {\r\n FALLBACK_ELEMENT_ID: \"powerdiary_fallback_btn\",\r\n IFRAME_ID: \"powerdiary_portal\",\r\n LOAD_TIMEOUT: 3000,\r\n BUTTON_TEMPLATE: 'Book Now >',\r\n BUTTON_TEMPLATE_STYLES:\r\n \"background: #0980fd;color: #fff;padding: 11px 40px;border-radius: 5px;margin: 5px 10px;display: inline-block;text-decoration: none;font-size: 1.2em;font-family: 'Roboto',sans-serif;display: block;width: 150px;text-align: center;margin: 0 auto;white-space: nowrap;box-sizing: content-box;\",\r\n FALLBACK_ELEMENT_DISPLAY: \"block\",\r\n };\r\n\r\n monitorIframeLoad() {\r\n const iframeId: string = this.getSettingValue(\"IFRAME_ID\");\r\n let loadTimeout: number = this.getSettingValue(\"LOAD_TIMEOUT\");\r\n if (loadTimeout <= 0) loadTimeout = 1;\r\n\r\n this.iframe = document.getElementById(iframeId) as HTMLIFrameElement;\r\n if (!this.iframe) {\r\n console.error(`PowerDiary: iframe with id=${iframeId} not found.`);\r\n return;\r\n }\r\n\r\n //this.iframe.addEventListener('load', this.handleIframeLoaded.bind(this));\r\n window.addEventListener(\"message\", (evt) => {\r\n if (evt.data === \"ClientPortalLoading\") this.handleIframeLoaded();\r\n });\r\n\r\n this.renderFallbackButtonHidden(this.iframe);\r\n\r\n (window as any).clientPortalTimeout = setTimeout(\r\n function () {\r\n PortalEmbedParent.log(\"iframe not loaded. Rendering fallback method.\");\r\n this.toggleFallbackMethod(true);\r\n }.bind(this),\r\n loadTimeout\r\n );\r\n }\r\n\r\n private getSettingValue(key: string): any {\r\n const userValue = (window as any)[\"PD_\" + key];\r\n if (typeof userValue !== \"undefined\") return userValue;\r\n return this.defaultSettings[key];\r\n }\r\n\r\n private renderFallbackButtonHidden(iframe: HTMLElement) {\r\n const fallbackElementId: string = this.getSettingValue(\"FALLBACK_ELEMENT_ID\");\r\n const styles = this.getSettingValue(\"BUTTON_TEMPLATE_STYLES\");\r\n let buttonTemplate = this.getSettingValue(\"BUTTON_TEMPLATE\");\r\n\r\n buttonTemplate = buttonTemplate.replace(\"{{url}}\", iframe.getAttribute(\"src\")).replace(\"{{styles}}\", styles);\r\n\r\n const button = PortalEmbedParent.createElementFromHTML(buttonTemplate);\r\n button.style.display = \"none\";\r\n button.id = fallbackElementId;\r\n iframe.parentNode.insertBefore(button, iframe.nextSibling);\r\n }\r\n\r\n private toggleFallbackMethod(show: boolean) {\r\n const fallbackElementId: string = this.getSettingValue(\"FALLBACK_ELEMENT_ID\");\r\n const fallbackElementDisplay: string = this.getSettingValue(\"FALLBACK_ELEMENT_DISPLAY\");\r\n\r\n // Show/hide fallback method\r\n const element = document.getElementById(fallbackElementId);\r\n element.style.display = show ? fallbackElementDisplay : \"none\";\r\n\r\n // Show/hide iframe (!show)\r\n this.iframe.style.display = show ? \"none\" : \"block\";\r\n }\r\n\r\n private static createElementFromHTML(html: string): HTMLElement {\r\n const div = document.createElement(\"div\");\r\n div.innerHTML = html;\r\n return div.firstChild as HTMLElement;\r\n }\r\n\r\n private handleIframeLoaded() {\r\n PortalEmbedParent.log(\"iframe loaded\");\r\n\r\n const win = window as any;\r\n win.clientPortalLoaded = true;\r\n clearTimeout(win.clientPortalTimeout);\r\n\r\n this.toggleFallbackMethod(false);\r\n }\r\n\r\n private static log(msg: string) {\r\n console.log(`PowerDiary: ${msg}`);\r\n }\r\n}\r\n\r\nnew PortalEmbedParent().monitorIframeLoad();\r\n"],"names":["PortalEmbedParent","constructor","iframe","defaultSettings","FALLBACK_ELEMENT_ID","IFRAME_ID","LOAD_TIMEOUT","BUTTON_TEMPLATE","BUTTON_TEMPLATE_STYLES","FALLBACK_ELEMENT_DISPLAY","monitorIframeLoad","iframeId","getSettingValue","loadTimeout","document","getElementById","console","error","window","addEventListener","evt","data","handleIframeLoaded","renderFallbackButtonHidden","clientPortalTimeout","setTimeout","log","toggleFallbackMethod","bind","key","userValue","fallbackElementId","styles","buttonTemplate","replace","getAttribute","button","createElementFromHTML","style","display","id","parentNode","insertBefore","nextSibling","show","fallbackElementDisplay","element","html","div","createElement","innerHTML","firstChild","win","clientPortalLoaded","clearTimeout","msg"],"sourceRoot":""}