jQuery( document ).ready(function( $ ) { var responsive_width = "991"; var browserWidth = $(window).width(); url = parent.document.URL; var iframe = document.createElement('iframe'); iframe.setAttribute('id', 'customer-chatbox'); iframe.setAttribute("src", "https://auditoriasaude.ipmfor.ce.gov.br/widget_content?url="+url); iframe.style.width = "80px"; iframe.style.height = "80px"; //Orginal Size 500 iframe.style.position = 'fixed'; iframe.style.overflow = 'hidden'; iframe.style.zIndex = 999999; iframe.setAttribute('hidden', 'true') iframe.style.right = 0; iframe.style.marginRight = '5px'; //iframe.style.marginBottom = '-374px'; iframe.style.bottom = 0; iframe.border = 0; iframe.marginwidth = 0; iframe.marginWidth = 0; iframe.marginheight = 0; iframe.marginHeight = 0; iframe.frameBorder = 0; document.body.appendChild(iframe); function checkUserStorage() { var userStorage = JSON.parse(localStorage.getItem('user')); var dependentsStorage = JSON.parse(localStorage.getItem('dependents')); var laboratorios = JSON.parse(localStorage.getItem('laboratorios')); var clinicas = JSON.parse(localStorage.getItem('clinicas')); var oftalms = JSON.parse(localStorage.getItem('oftalms')) var x = document.getElementById("customer-chatbox"); urlSplit = parent.document.URL.split('/'); if(userStorage && urlSplit[urlSplit.length -1] !== "home" && urlSplit[urlSplit.length -1] !== "#"){ let matriculaIPMSaude = localStorage.getItem('matriculaIPMSaude'); var nome = userStorage.nome; var matricula = userStorage.servidor_CMF == true ? matriculaIPMSaude: userStorage.matricula; var email = userStorage.email; var nomeDependentes = []; if (dependentsStorage.length > 0) { for (var i = 0; i < dependentsStorage.length; i++) { nomeDependentes.push(dependentsStorage[i].nome); } } x.contentWindow.postMessage('matricula', '*'); x.contentWindow.postMessage({"nome": nome, "matricula": matricula, "email": email, "dependents": nomeDependentes, "laboratorios": laboratorios.labs, "clinicas": clinicas.clin, "oftalms": oftalms.oftal }, '*'); }else { x.contentWindow.postMessage('convidado', '*'); } } window.addEventListener('message', receiveMessage, false); $(window).on('hashchange', function(e) { minimizeChat(); var x = document.getElementById("customer-chatbox"); x.contentWindow.postMessage('logoutUser', '*'); }); function receiveMessage(event) { if(event.data == "page_reload") { window.location.reload(); } if(event.data == "show_"){ var x = document.getElementById("customer-chatbox"); //check if window is full screen if($(window).width() > responsive_width){ x.style.width = "400px"; x.style.height = "600px"; x.contentWindow.postMessage('small_screen', '*'); } if($(window).width() <= responsive_width){ x.style.width = "100%"; x.style.height = "100%"; x.contentWindow.postMessage('responsive', '*'); } checkUserStorage(); } if(event.data == "hide_"){ var x = document.getElementById("customer-chatbox"); //check if window is full screen if($(window).width() > responsive_width){ x.style.width = "80px"; x.style.height = "80px"; x.contentWindow.postMessage('small_screen', '*'); } if($(window).width() <= responsive_width){ x.style.width = "80px"; x.style.height = "80px"; x.contentWindow.postMessage('responsive', '*'); } } } function minimizeChat(){ if($(window).width() <= responsive_width){ var x = document.getElementById("customer-chatbox"); x.style.width = "80px"; x.style.height = "80px"; x.style.marginRight = "0"; x.contentWindow.postMessage('responsive', '*'); x.contentWindow.postMessage('class_down', '*'); }else{ var x = document.getElementById("customer-chatbox"); x.style.width = "80px"; x.style.height = "80px"; x.style.marginRight = "5px"; x.contentWindow.postMessage('desktop', '*'); x.contentWindow.postMessage('class_down', '*'); } } });