const openOnLoad = false
let chatOpen = false;
let chatLoaded = false;
function preloadChat() {
const chat = document.getElementById('chatbot-d66e340eb515047c-chat');
if (!chatLoaded) {
chat.insertAdjacentHTML('');
chatLoaded = true;
}
}
function closePoppupMsg(event) {
localStorage.setItem('closePopupMsg', true)
const msgPoppup = document.getElementsByClassName('cnx-glow-container');
for (let i = 0; i < msgPoppup.length; i++) {
const msg = msgPoppup[i];
msg.style.display = 'none';
}
}
function toggleChat() {
localStorage.setItem('closePopupMsg', true)
const chat = document.getElementById('chatbot-d66e340eb515047c-chat');
const tooltips = document.getElementsByClassName('cnx-glow-container');
const chatButton = document.getElementById('toggle-btn-d66e340eb515047c');
const closeButton = document.getElementById('close-btn-d66e340eb515047c');
for (let i = 0; i < tooltips.length; i++) {
const tooltip = tooltips[i];
if (tooltip){
tooltip.style.visibility = 'hidden';
}
}
if (!chatLoaded) {
chat.innerHTML += '';
chatLoaded = true;
}
if (chatOpen) {
window.parent.postMessage({ type: 'closeChat' }, '*');
} else {
chat.classList.add('open');
chatButton.classList.add('open');
}
chatOpen = !chatOpen;
}
let configs = {};
function iframeLoaded() {
const chat = document.getElementById('chatbot-' + 'd66e340eb515047c' + '-chat');
}
function getSearchParams() {
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
const queryParamsArray = [];
for (const [key, value] of params.entries()) {
queryParamsArray.push({ key, value });
}
return queryParamsArray
}
function handleDOMContentReady() {
const currentScript = document.currentScript;
if (currentScript) {
const attributes = currentScript.getAttributeNames().filter(x => x.startsWith('data-'))
if (attributes.length) {
for (const attribute of attributes) {
configs[attribute.replace('data-', '')] = currentScript.getAttribute(attribute);
}
}
const searchParams = getSearchParams()
if (searchParams.length) {
for (const searchParam of searchParams) {
configs[searchParam.key.replace('data-', '')] = searchParam.value;
}
}
}
try {
const allowedDomains = ["*"];
if (allowedDomains.includes('*') || allowedDomains.includes(window.location.host)) {
const body = document.querySelector('body');
body.insertAdjacentHTML('beforeend', `
`);
body.style.margin = '0';
if (openOnLoad) {
toggleChat();
}
setupPopper();
const btnClose = document.getElementById('close-btn-glow-id');
const containerPoppup = document.getElementById('cnx-glow-main');
containerPoppup?.addEventListener('mouseenter', function () {
btnClose.style.display = 'flex';
});
containerPoppup?.addEventListener('mouseleave', function () {
btnClose.style.display = 'none';
});
if(localStorage.getItem('d66e340eb515047c-for-agent')) {
preloadChat();
}
}
}catch (error) {
console.error("Error initializing the chatbot script:", error);
}
};
if (document.readyState === 'loading') {
// The document is still loading, add the event listener
document.addEventListener('DOMContentLoaded', handleDOMContentReady);
} else {
// DOMContentLoaded has already fired
handleDOMContentReady();
}
function sleep(milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
async function setupPopper() {
const chatButton = document.getElementById('toggle-btn-d66e340eb515047c');
const closePopupMsg = Boolean(localStorage.getItem('closePopupMsg'));
const containerPoppup = document.getElementById('cnx-glow-main');
if(containerPoppup) containerPoppup.style.display = 'none';
if(!closePopupMsg) {
const tooltips = document.getElementsByClassName('cnx-glow-box');
sleep(2000).then(() => {
if (containerPoppup) containerPoppup.style.display = 'flex';
for (let i = 0; i < tooltips.length; i++) {
(function (index) {
setTimeout(() => {
const tooltip = tooltips[index];
if (tooltip) {
tooltip.style.opacity = 1;
}
}, index * 300); // Delay each iteration by 300ms times the index
})(i);
}
});
}
function initializeChat() {
const inner_iframe = document.getElementById('inner-iframe');
if(inner_iframe) {
const inner_iframe_window = inner_iframe.contentWindow;
inner_iframe_window.postMessage({
type: 'initializeChat',
...configs
}, '*');
}
}
function sendDimensions() {
const inner_iframe = document.getElementById('inner-iframe');
if(inner_iframe) {
const inner_iframe_window = inner_iframe.contentWindow;
inner_iframe_window.postMessage({
type: 'parentSize',
width: window.innerWidth,
height: window.innerHeight
}, '*');
}
}
function closeChat() {
const chat = document.getElementById('chatbot-d66e340eb515047c-chat');
const chatButton = document.getElementById('toggle-btn-d66e340eb515047c');
const tooltip = document.getElementById('chat-popup-tooltip');
const closeButton = document.getElementById('close-btn-d66e340eb515047c');
chat.classList.remove('open');
chatButton.classList.remove('open');
if (chatOpen) {
chat.classList.remove('open');
// Optionally, hide the tooltip if it was displayed
if (tooltip) {
tooltip.style.display = 'none';
}
// Ensure the global state reflects the chat is now closed
chatOpen = false;
}
}
function resizeMobileChat() {
const chat = document.getElementById('chatbot-d66e340eb515047c-chat');
const initalViewportHeight = window.innerHeight;
chat.style.height = initalViewportHeight + 'px';
}
// Window event listeners
window.addEventListener('message', (event) => {
if (event.data.type === 'closeChat') {
closeChat();
} else if (event.data.type === 'headerReady') {
sendDimensions();
initializeChat();
}
});
window.addEventListener('resize', () => {
resizeMobileChat();
sendDimensions();
});
const toggleButton = document.getElementById('toggle-btn-d66e340eb515047c');
toggleButton.addEventListener('click', (event) => {
if (document.documentElement.clientWidth < 767) {
resizeMobileChat();
}
});
// Tooltip positioning & extra
// if (tooltip && '' === 'top' && true === false) {
// tooltip.classList.add('cnx-move-left');
// } else if (tooltip && '' === 'top' && true === true) {
// tooltip.classList.add('cnx-move-right');
// }
if (document.documentElement.clientWidth < 767) {
setTimeout(() => {
const tooltip = document.getElementById('cnx-glow-main');
tooltip.style.display = 'none';
}, 5000);
}
}