(function() {
'use strict';
const chatWebsiteAddressOrigin = 'https://azzurro.it'
if(chatWebsiteAddressOrigin !== window.location.origin){
alert(`The current location does not match ${chatWebsiteAddressOrigin}. Please check your website domain in the current XCALLY Chat Website settings.`)
}
else
{
// Init all URLs
const remoteURL = new URL('https://proxy2.inovasj.com')
const chatOrigin = remoteURL.origin
const chatPath = '/snippet/'
const chatStylesPath = chatPath + 'styles/'
const chatVersion = '3.5.0'
// Style setttings
const divColor = '#83afe1'
const textColor = '#000000'
const buttonColor = '#3b8b9f'
const backgroungColor = '#ffffff'
let alignment = "bottom_right";
let verticalAlignment = "30";
// iframe URL settings
const iframeId = 'motion-chat-iframe'
const iframeSrcURL = new URL(chatPath, chatOrigin)
const iframeSearchParams = new URLSearchParams('onlineForm=&offlineForm=&id=1&name=WebChat&address=https%3A%2F%2Fazzurro.it&description=Chat%20sito%20Azzurro.it&mapKey=firstName&mapKeyOffline=email&key=TACht&agentAlias=Agent&customerAlias=Me&color=%2383afe1&color_button=%233b8b9f&textColor=%23000000&textButtonColor=%23000000&fontSize=15&remote=https%3A%2F%2Fproxy2.inovasj.com&animation=true&header_shape=rounded&header_online=Siamo%20online%20%3A)&start_chat_button=Chat&offline_chat_button=Send&header_offline=Contact%20us&download_transcript=true&timeout=0&whiteLabel=Powered%20by%20xCALLY&defaultWhiteLabel=true&sitepic=&closingQuestion=Vuoi%20chiudere%20l\'interazione%3F&formSubmitSuccessMessage=Form%20properly%20submitted&formSubmitFailureMessage=Form%20submission%20error¬eTitle=&placeholderMessage=Type%20a%20message&closingMessage=Grazie%20per%20aver%20chattato%20con%20noi!%20Ti%20chiediamo%20ora%20di%20aiutarci%20a%20migliorare%20la%20nostra%20chat%20rispondendo%20ad%20alcune%20domande%3A%20%3Ca%20href%3D%E2%80%9Dhttps%3A%2F%2Fit.surveymonkey.com%2Fr%2Faiutaci%E2%80%9D%3E%20Clicca%20qui%20per%20raggiungere%20la%20pagina%3C%2Fa%3E&closingMessageButton=Send&skipMessageButton=esci&conditionAgreement=false&enableRating=false&enableFeedback=false&enableSendButton=false&feedbackTitle=Feedback&ratingType=star&ratingStarsNumber=5&token=RzaYH3G6us2u7YNVmlkQtER9rvd8K0np&autoclose=true&enableCustomerWriting=false&forwardTranscript=false&forwardTranscriptMessage=&forwardOffline=false&forwardOfflineAddress=&waitingTitle=La%20tua%20chat%20%C3%A8%20molto%20importante%20per%20noi&waitingMessage=Per%20favore%20attendi%20un%20momento%2C%20ti%20risponderemo%20il%20prima%20possibile&offlineMessageSubject=New%20offline%20message%20from%20websiteName&offlineMessageBody=You%20received%20a%20new%20offline%20message%20from%20websiteName.%20Here%20you%20can%20find%20the%20details%20of%20the%20request%3A&enableUnmanagedNote=false&unmanagedMessage=Tutti%20i%20nostri%20operatori%20sono%20impegnati%2C%20ti%20invitiamo%20a%20riprovare%20pi%C3%B9%20tardi.%20Grazie&skipUnmanaged=ESCI&sendUnmanaged=Send&enableCustomerAttachment=false&enableCustomerCheckmarks=false&agentAvatar=1553185056943-logo_TA.jpg&showAgentAvatar=true&timezone=¬ificationTemplate=%3Cp%3EAccount%3A%20%7B%7Baccount.name%7D%7D%3Cbr%20%2F%3E%0A%7B%7B%23queue%7D%7DQueue%3A%20%7B%7Bqueue.name%7D%7D%3Cbr%20%2F%3E%0A%7B%7B%2Fqueue%7D%7DFrom%20%3A%20%7B%7Bfrom%7D%7D%3C%2Fp%3E%0A¬ificationSound=true¬ificationShake=true&hideWhenOffline=true&agentIdentifier=agent_alias&waitForTheAssignedAgent=120&waitForTheAssignedQueue=10&alignment=bottom_right&verticalAlignment=30&labelText=CHAT&messagesAlignment=alternate&defaultTitle=--CHAT--&customerAvatar=&showCustomerAvatar=true&messageFontSize=12&backgroundColor=%23ffffff&queueTransfer=true&queueTransferTimeout=120&agentTransfer=true&agentTransferTimeout=120&systemAlias=System&systemAvatar=&mandatoryDispositionPauseId=2&mandatoryDisposition=true&vidaooEscalation=false&vidaooApiKey=&vidaooTopic=Generated%20by%20XCALLY%20Motion&vidaooNote=Meeting%20generated%20for%20interaction%20%20%23%7B%7Binteraction.id%7D%7D%20by%20%7B%7Bagent.name%7D%7D&vidaooMetadata=&openNewInteraction=false&subjectOffline=&createdAt=&updatedAt=&ListId=1&IntervalId=&MailAccountId=&Interval=&customerIp=54.224.43.79%2C%20185.43.211.134&referer=&openedInteractions=0&maxInteractions=30&virtual=&online=true&custom=false')
iframeSearchParams.append('version', chatVersion)
iframeSearchParams.append('location', btoa(window.location.host))
iframeSrcURL.search = iframeSearchParams
// Style URL settings
const linkURL = new URL(chatStylesPath + 'mobile.css', chatOrigin)
linkURL.search = new URLSearchParams({ version: chatVersion })
const linkMobile = document.createElement('link');
linkMobile.type = "text/css";
linkMobile.rel='stylesheet';
linkMobile.href = linkURL.toString()
// Iframe localstorage whitelisting
const allowedOrigins = [chatOrigin]
function remoteLocalStorageEventHandler(event){
if (allowedOrigins.includes(event.origin)) {
const { action, key, value } = event.data
const localStorage = window.localStorage
switch(action){
case 'setItem':
{
localStorage.setItem(key, JSON.stringify(value))
event.source.postMessage(
{
action: 'setItemResult',
key
}, event.origin)
}
break
case 'getItem':
{
let item = localStorage.getItem(key)
if(item){
try {
item = JSON.parse(item)
} catch (error) {
console.error('Cannot read data from localstorage', error)
}
}
event.source.postMessage(
{
action: 'getItemResult',
key,
item
}, event.origin)
}
break
case 'removeItem':
{
localStorage.removeItem(key)
event.source.postMessage(
{
action: 'removeItemResult',
key
}, event.origin)
}
break
default:
typeof action === 'string' && console.debug('Unsupported action', action)
break;
}
}
}
// DOM Manipulation
let iframe = document.createElement('iframe');
// Attributes
iframe['id'] = iframeId;
iframe['src'] = iframeSrcURL.toString()
let iframe_status = false;
document.documentElement.style.setProperty('--xc-ws-div-color', divColor);
document.documentElement.style.setProperty('--xc-ws-text-color', textColor);
document.documentElement.style.setProperty('--xc-ws-button-color', buttonColor);
document.documentElement.style.setProperty('--xc-ws-background-color', backgroungColor);
document.head.appendChild(linkMobile);
// Bottom, right
iframe.className = 'motion-chat-iframe-bottom_right';
verticalAlignment = 0;
document.body.appendChild(iframe);
// START Events management
window.addEventListener('message', function(evt) {
remoteLocalStorageEventHandler(evt)
switch (evt.data.cmd) {
case 'show':
// Bottom, right
iframe.style.top = 'auto';
iframe.style.bottom = '0px';
break;
case 'hide':
// Bottom, right
iframe.style.top = 'calc(100% - 50px)';
break;
case "init":
break;
case "offline":
break;
default:
}
}, false);
// END Events management
// START Proactive action management
// END Proactive action management
if (window.DeviceOrientationEvent) {
window.addEventListener('orientationchange', function() {
if (alignment == 'right'){
document.getElementById("chat_tab_arrow").innerHTML = " < ";
let iframeEl = document.getElementById('motion-chat-iframe');
iframeEl.contentWindow?.postMessage({"evt":"hide"}, '*');
tab_status = 0;
iframe_h = topIframe_calc();
topIframe_set(iframe_h);
if(typeof div_tab != "undefined") topChat_set(iframe_h, verticalAlignment);
}
else if (alignment == 'left'){
document.getElementById("chat_tab_arrow").innerHTML = " > ";
let iframeEl = document.getElementById('motion-chat-iframe');
iframeEl.contentWindow?.postMessage({"evt":"hide"}, '*');
tab_status = 0;
iframe_h = topIframe_calc();
topIframe_set(iframe_h);
if(typeof div_tab != "undefined") topChat_set(iframe_h, verticalAlignment);
} }, false);
}
window.addEventListener("resize", function(event) {
let iframe_h = topIframe_calc();
topIframe_set(iframe_h);
if(typeof div_tab != "undefined") topChat_set(iframe_h, verticalAlignment);
});
function topIframe_calc(){
let height_iframe
let heightD = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
let iframeT = ((heightD/100)*verticalAlignment) + 450;
if (heightD < iframeT) {
height_iframe = 450 - (iframeT - heightD);
}
else { height_iframe = 450; }
return height_iframe;
}
function topIframe_set(height_iframe){
if( height_iframe > 340){
iframe.style['height'] = height_iframe +'px';
if (alignment == "right" || alignment == "left" )
{ iframe.style['top'] = verticalAlignment + "%"; }
else{ iframe.style['bottom'] = "0%"; }
}
else {
iframe.style['height'] = '340px';
if (alignment == "right" || alignment == "left" )
{ iframe.style['top'] = "calc(100% - 340px)"; }
else{ iframe.style['bottom'] = "0%"; }
}
}
function topChat_set(height_iframe, verticalAlignment){
if( height_iframe > 340){
div_tab.style['top'] = "calc("+ verticalAlignment +"% + " + (height_iframe - 100) + "px)";
}
else {
div_tab.style['top'] = "auto";
div_tab.style['bottom'] = "0px";
}
}
// hide chat
}
}());