| 12345678910111213 |
- (function(){const href=window.location.href;const queryString=href.includes('?')?href.split('?')[1]:'';const urlParams=queryString?'?'+queryString:'';const zopimWidget=document.getElementById('zopim-widget');if(zopimWidget){zopimWidget.src=urlParams?'https://secure.cwgmx.com/mobile/zopim.html'+urlParams:'./zopim.html'}})();window.addEventListener('message',function(event){const zopimWidget=document.getElementById('zopim-widget');if(!zopimWidget)return;if(event.data&&typeof event.data==='object'){const{type,isHidden}=event.data;if(type==='chatWidgetStatus'){const dragHandle=document.getElementById('zopim-drag-handle');if(isHidden){zopimWidget.style.width='100px';zopimWidget.style.height='100px';zopimWidget.style.bottom='60px';zopimWidget.style.right='auto';zopimWidget.style.left='0';if(dragHandle){dragHandle.style.display='block'}}else{zopimWidget.style.width='100%';zopimWidget.style.height='100vh';zopimWidget.style.bottom='0';zopimWidget.style.left='0';zopimWidget.style.right='auto';zopimWidget.style.top='auto';if(dragHandle){dragHandle.style.display='none'}}}}});function initIframeDraggable(){let checkCount=0;const checkInterval=setInterval(()=>{const iframe=document.getElementById('zopim-widget');checkCount++;if(iframe){clearInterval(checkInterval);function onMinimizedReady(event){if(event.data&&event.data.type==='chatWidgetMinimizedReady'){window.removeEventListener('message',onMinimizedReady);makeIframeDraggable(iframe)}}
- window.addEventListener('message',onMinimizedReady)}else if(checkCount>20){clearInterval(checkInterval)}},500)}
- function makeIframeDraggable(iframe){let isDragging=!1;let hasMoved=!1;let startX,startY,initialLeft,initialTop;const DRAG_THRESHOLD=5;const dragHandle=document.createElement('div');dragHandle.id='zopim-drag-handle';dragHandle.style.cssText='position:fixed;'+'inset:auto auto 60px 0px;'+'width:100px;'+'height:100px;'+'background:transparent;'+'cursor:move;'+'z-index:1000000;'+'pointer-events:auto;';document.body.appendChild(dragHandle);let clickTimer=null;dragHandle.addEventListener('click',handleClick);dragHandle.addEventListener('mousedown',startDrag);dragHandle.addEventListener('touchstart',startDrag,{passive:!1});let iframeReady=!1;iframe.addEventListener('load',function(){iframeReady=!0});function sendMessageToIframe(message){if(!iframe.contentWindow)return;try{const iframeSrc=iframe.src;let targetOrigin='*';if(iframeSrc){try{const url=new URL(iframeSrc);targetOrigin=url.origin}catch(e){targetOrigin='*'}}
- iframe.contentWindow.postMessage(message,targetOrigin)}catch(error){iframe.contentWindow.postMessage(message,'*')}}
- function handleClick(e){if(hasMoved){e.preventDefault();e.stopPropagation();return}
- if(clickTimer){clearTimeout(clickTimer);clickTimer=null;return}
- clickTimer=setTimeout(()=>{clickTimer=null;sendMessageToIframe({type:'openChat'})},250)}
- function startDrag(e){isDragging=!0;hasMoved=!1;const touch=e.type==='touchstart'?e.touches[0]:e;startX=touch.clientX;startY=touch.clientY;const rect=iframe.getBoundingClientRect();initialLeft=rect.left;initialTop=rect.top;document.addEventListener('mousemove',drag);document.addEventListener('touchmove',drag,{passive:!1});document.addEventListener('mouseup',stopDrag);document.addEventListener('touchend',stopDrag)}
- function drag(e){if(!isDragging)return;const touch=e.type==='touchmove'?e.touches[0]:e;const deltaX=touch.clientX-startX;const deltaY=touch.clientY-startY;const distance=Math.sqrt(deltaX*deltaX+deltaY*deltaY);if(!hasMoved&&distance>DRAG_THRESHOLD){hasMoved=!0;dragHandle.style.cursor='grabbing'}
- if(hasMoved){e.preventDefault();e.stopPropagation();const newLeft=initialLeft+deltaX;const newTop=initialTop+deltaY;const maxLeft=window.innerWidth-iframe.offsetWidth;const maxTop=window.innerHeight-iframe.offsetHeight;const boundedLeft=Math.max(0,Math.min(newLeft,maxLeft));const boundedTop=Math.max(0,Math.min(newTop,maxTop));iframe.style.left=boundedLeft+'px';iframe.style.top=boundedTop+'px';iframe.style.right='auto';iframe.style.bottom='auto';dragHandle.style.left=boundedLeft+'px';dragHandle.style.top=boundedTop+'px';dragHandle.style.right='auto';dragHandle.style.bottom='auto'}}
- function stopDrag(e){if(!isDragging)return;document.removeEventListener('mousemove',drag);document.removeEventListener('touchmove',drag);document.removeEventListener('mouseup',stopDrag);document.removeEventListener('touchend',stopDrag);if(hasMoved){if(e){e.preventDefault();e.stopPropagation()}}else{iframe.style.left='0';iframe.style.top='auto';iframe.style.right='auto';iframe.style.bottom='60px';dragHandle.style.left='0';dragHandle.style.top='auto';dragHandle.style.right='auto';dragHandle.style.bottom='60px';iframe.contentWindow.postMessage({type:'openChat'},'*')}
- isDragging=!1;setTimeout(()=>{hasMoved=!1},50);dragHandle.style.cursor='move'}}
- document.addEventListener('DOMContentLoaded',initIframeDraggable)
|