(function () { if (window.__livechatWidgetLoaded) { return; } window.__livechatWidgetLoaded = true; var config = {"color":"#1e9fff","leftorright":"right","bottom":"100px","target":"3","auto_popup":"1","livechaturl":"\/livechat\/"}; if (!config.livechaturl) { return; } function normalizeSide(value) { value = String(value || '').toLowerCase(); return value.indexOf('left') !== -1 ? 'left' : 'right'; } function normalizeBottom(value) { value = String(value || '').replace(/^\s+|\s+$/g, ''); if (!value) { return '30px'; } if (/^\d+$/.test(value)) { return value + 'px'; } if (/^\d+(\.\d+)?(px|%)$/.test(value)) { return value; } return '30px'; } function normalizeTarget(value) { value = parseInt(value, 10); if (value !== 1 && value !== 2 && value !== 3) { return 3; } return value; } var side = normalizeSide(config.leftorright); var bottom = normalizeBottom(config.bottom); var target = normalizeTarget(config.target); var autoPopup = parseInt(config.auto_popup, 10) === 1; var color = config.color || '#1677ff'; var widgetId = 'livechat-widget-root'; var panelId = 'livechat-widget-panel'; var buttonId = 'livechat-widget-button'; var styleId = 'livechat-widget-style'; var popupKey = 'livechat_widget_auto_popup_shown'; function addStyle() { if (document.getElementById(styleId)) { return; } var sideOffset = side === 'left' ? 'left: 30px;' : 'right: 30px;'; var panelOffset = side === 'left' ? 'left: 30px;' : 'right: 30px;'; var style = document.createElement('style'); style.id = styleId; style.type = 'text/css'; style.appendChild(document.createTextNode( '' + '#' + widgetId + '{position:fixed;' + sideOffset + 'bottom:' + bottom + ';z-index:999999;display:flex;flex-direction:column;align-items:' + (side === 'left' ? 'flex-start' : 'flex-end') + ';}' + '@keyframes livechat-breathe{0%,100%{transform:scale(1);opacity:0.7}50%{transform:scale(1.15);opacity:1}}' + '#' + buttonId + '{width:56px;height:56px;border-radius:50%;background:' + color + ';box-shadow:0 10px 30px rgba(0,0,0,.18);cursor:pointer;display:flex;align-items:center;justify-content:center;border:none;padding:0;outline:none;transition:all .2s ease;flex-shrink:0;}' + '#' + buttonId + ':hover{transform:translateY(-2px);box-shadow:0 14px 34px rgba(0,0,0,.24);}' + '#' + buttonId + ':hover svg{animation-play-state:paused;}' + '#' + buttonId + ' svg{width:28px;height:28px;fill:#fff;display:block;animation:livechat-breathe 1.6s ease-in-out infinite;}' + '#' + panelId + '{position:fixed;' + panelOffset + 'bottom:calc(' + bottom + ' + 72px);width:min(380px,calc(100vw - 32px));height:min(620px,70vh);background:#fff;border-radius:16px;box-shadow:0 20px 60px rgba(0,0,0,.22);overflow:hidden;z-index:999999;display:none;opacity:0;transform:scale(0.8) translateY(10px);transform-origin:' + (side === 'left' ? 'left' : 'right') + ' bottom;transition:opacity .25s ease,transform .25s ease;}' + '#' + panelId + '.is-open{display:block;opacity:1;transform:scale(1) translateY(0);}' + '#' + panelId + ' iframe{width:100%;height:100%;border:none;background:#fff;display:block;}' + '@media (max-width: 640px){' + '#' + widgetId + '{' + side + ':28px;bottom:' + bottom + ';}' + '#' + panelId + '{left:12px !important;right:12px !important;bottom:84px;width:auto;height:72vh;border-radius:14px;}' + '}' )); document.head.appendChild(style); } function openNewWindow() { window.open(config.livechaturl, 'livechat_window', 'noopener'); } function getPanel() { return document.getElementById(panelId); } function closePanel() { var panel = getPanel(); if (panel) { panel.className = panel.className.replace(/\s*is-open\s*/g, ' '); setTimeout(function() { if (panel.parentNode) { panel.parentNode.removeChild(panel); } }, 300); } } function handleMessage(event) { var data = event && event.data; if (!data || data.type !== 'livechat_widget_close') { return; } closePanel(); } function openPanel() { var panel = getPanel(); if (!panel) { panel = document.createElement('div'); panel.id = panelId; panel.innerHTML = ''; document.body.appendChild(panel); panel.offsetHeight; } var btn = document.getElementById(buttonId); if (btn) { var btnRect = btn.getBoundingClientRect(); var btnCenterY = btnRect.top + btnRect.height / 2; if (btnCenterY < window.innerHeight / 2) { panel.style.bottom = 'auto'; panel.style.top = (btnRect.bottom + 16) + 'px'; panel.style.height = Math.min(620, window.innerHeight - btnRect.bottom - 32) + 'px'; panel.style.maxHeight = Math.min(620, window.innerHeight - btnRect.bottom - 32) + 'px'; } else { panel.style.top = 'auto'; panel.style.bottom = ''; panel.style.height = ''; panel.style.maxHeight = ''; } } if (panel.className.indexOf('is-open') === -1) { panel.className = (panel.className ? panel.className + ' ' : '') + 'is-open'; } } function togglePanel() { var panel = getPanel(); if (panel && panel.className.indexOf('is-open') !== -1) { closePanel(); return; } openPanel(); } function handleOpen() { if (target === 2) { openNewWindow(); return; } if (target === 3 && window.innerWidth < 1000) { openNewWindow(); return; } togglePanel(); } function createWidget() { if (!document.body || document.getElementById(widgetId)) { return; } addStyle(); window.livechatWidgetClose = closePanel; if (!window.__livechatWidgetMessageBound) { window.__livechatWidgetMessageBound = true; window.addEventListener('message', handleMessage, false); } var root = document.createElement('div'); root.id = widgetId; var button = document.createElement('button'); button.id = buttonId; button.type = 'button'; button.setAttribute('aria-label', 'Open live chat'); button.innerHTML = ''; button.onclick = handleOpen; root.appendChild(button); document.body.appendChild(root); if (autoPopup) { var alreadyShown = sessionStorage.getItem(popupKey); if (!alreadyShown) { setTimeout(function() { if (!sessionStorage.getItem(popupKey)) { sessionStorage.setItem(popupKey, '1'); if (target === 2) { openNewWindow(); } else if (target === 3 && window.innerWidth < 1000) { openNewWindow(); } else { openPanel(); } } }, 1500); } } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', createWidget); } else { createWidget(); } })();