(function() { /** * */ var iFRAME_SRC = "https://us-central1-feedback-kit.cloudfunctions.net/api/feedback?uid=prod_statement_download×tamp=1714212100947"; var TTL = '2592000'; var INSTANCE_ID = 'feedback_prod_statement_download'; var STATUS = 'hidden'; /** * Check if iframe is loaded */ var iFrameLoaded = false var feedback_kit_iframe = null; var loader = null; /** * Styles */ var iFrameStyle = "z-index: 99999999999999999;height: 98%;width: 100%;display: none;margin: auto;background: rgba(96,96,96,.2); position: fixed;top:0;bottom:0;left:0;right:0"; var loaderStyle = "z-index: 99999999999999998;height: 98%;width: 100%;display: block;margin: auto; text-align: center;position:fixed;fixed;top:0;bottom:0;left:0;right:0;background-position: center; background:url(img/loader.gif);background-repeat: no-repeat;background-attachment: fixed;background-position: center;"; /** * Cross origin communication */ var fnMap = { show: showFn, hide: hideFn, } window['statement_download_feedback_type'] = fnMap /** * Load IFrame */ function loadFn(callback) { if (feedback_kit_iframe === null) { // Create IFrame feedback_kit_iframe = document.createElement("IFRAME"); // Set ID feedback_kit_iframe.id = INSTANCE_ID // Set SRC feedback_kit_iframe.src = iFRAME_SRC; // Remove border and scrolling feedback_kit_iframe.frameBorder = "0" feedback_kit_iframe.scrolling = "No" // Add Style feedback_kit_iframe.style = iFrameStyle // Add onLoad Listener feedback_kit_iframe.onload = onLoadFn.bind(null,callback); // Add to DOM document.body.append(feedback_kit_iframe) onStartLoading(); iFrameLoaded = true }else{ callback(); } } /** * On Start IFrame Loading */ function onStartLoading() { //console.log('Started', new Date()); loader = document.createElement("div"); loader.style = loaderStyle; document.body.append(loader); } /** * On Load IFrame */ function onLoadFn(callback) { //console.log('Loaded', new Date()); callback(); if (loader != null) { loader.remove(); } } function isValid() { value = getCookie(INSTANCE_ID); return value === "" } /** * Show Modal */ function showFn(context) { if (isValid()) { loadFn(function(){ sendMessage('show',context) }); feedback_kit_iframe.style.display = 'block'; } } /** * Hide Modal */ function hideFn() { if(feedback_kit_iframe){ feedback_kit_iframe.style.display = 'none'; } } /** * Function to send message */ function sendMessage(fnName, args) { feedback_kit_iframe.contentWindow.postMessage({ fnName: fnName, args: args }, iFRAME_SRC); } /** * Function on receive message */ function receiveMessage(event) { //console.log("Parent ReceiveMessage : ", event) // If message received from unexpected origin don't process if (!(iFRAME_SRC.startsWith(event.origin) && ( event && event.data && event.data.instance_id === INSTANCE_ID ))) return; const message = event.data; // Process Event fnMap[message.fnName](message.args); if(message.fnName==="hide"){ setCookie(INSTANCE_ID, STATUS, TTL)} } /** * On Receive Event Listener */ window.addEventListener("message", receiveMessage, false); function setCookie(cname, cvalue, seconds) { var d = new Date(); d.setTime(d.getTime() + (Number(seconds)*1000)); var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;"; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } })()