//When user click on start free chat button post message to iframe, //The live person will open the live chat if (document.querySelector('#LivePerson')) { $(window).on("load", function () { var isFocusSet = false; var chatButtonSelector = '.multiflyout-button'; var iFrameWindowIDSelector = 'lpSS_89316509127'; var iFrameDomainUrlAttrName = 'data-domainUrl'; var flyoutContainerIdSelector = 'lp-iframe-container'; var ariaHiddenAttrName = 'aria-hidden'; var proactiveChatNowSelector = '.lp-chatnow'; var proactiveNoThanksSelector = '.lp-nothanks'; //Initialize IP cookies var lpInitializeAttrName = 'data-islpinitialized'; var lpConsentRequiredAttrName = 'data-isConsentRequired'; //var proactiveChatButtonSelector = '.proactive-invite-button'; var iFrameInDom, targetDomain, topicName, flyoutContainer, previouslyFocusedElement; var chatButton = document.getElementById("top-multiflyout-button"); findIFrameElements(); overrideIframeUrlBasedOnExperimentation(); if (iFrameInDom && !iFrameInDom.hasAttribute('data-deferChatComponent')) { // move to the bottom of the dom $('body').append($('#msChatContainer')); } $('body').on('click', chatButtonSelector, function (event, data) { if (data === null || data === undefined) { findIFrameElements(); flyoutContainer.setAttribute(ariaHiddenAttrName, 'false'); if ($('body').attr(lpInitializeAttrName) === 'false') { postMessage({ action: 'initializeLP' }); $('body').attr(lpInitializeAttrName, 'true'); } sendTopicMessage(); sendParentSizeMessage(); postMessage({ action: 'open' }); changeIFrameAttributesInMobile("True","dialog") } }); $('body').on('click', proactiveChatNowSelector, function (event) { findIFrameElements(); if (!flyoutContainer.hasAttribute(lpInitializeAttrName)) { iFrameInDom.contentWindow.postMessage({ action: 'initializeLP'}, targetDomain); } sendTopicMessage(); sendParentSizeMessage(); sendProactiveInviteMessage('accepted'); changeIFrameAttributesInMobile("True","dialog") }); $('body').on('click', proactiveNoThanksSelector, function (event) { sendProactiveInviteMessage('declined'); setChatWindowVisibility(false); }); initializeChatComponent(); function initializeChatComponent() { $('#' + iFrameWindowIDSelector).on('load', function() { sendDOMParentReadyMessage(); LPCookieConsent(); window.addEventListener("message", receiveMessage, false); window.addEventListener("resize", resizeHandler, false); document.body.addEventListener("keyup", keyUpHandler, false); updateViewPortMetaTagInMobileCanvas(); // Show the chat button when the iframe is loaded and the event handlers are registered chatButton.style.visibility = "visible"; }); iFrameInDom = document.getElementById(iFrameWindowIDSelector); if (iFrameInDom.getAttribute('data-iframeSrc') && iFrameInDom.getAttribute('data-iframeSrc') !== "") { iFrameInDom.setAttribute("src", iFrameInDom.getAttribute('data-iframeSrc')); } } function sendDOMParentReadyMessage() { findIFrameElements(); if(iFrameInDom && targetDomain){ postMessage({ action: 'DOMParentReady' }); //setting the data-ismobile attribute on iframe and also adding the css class lp-iframe-mobile to the iframe container to load correctly on mobile setIsMobile(); } } function findIFrameElements() { if (!iFrameInDom) { iFrameInDom = document.getElementById(iFrameWindowIDSelector); } if (!targetDomain) { targetDomain = iFrameInDom.getAttribute(iFrameDomainUrlAttrName); } if (!flyoutContainer) { flyoutContainer = document.getElementById(flyoutContainerIdSelector); } } function overrideIframeUrlBasedOnExperimentation() { //Below Qsp code is only used for testing since target is unavailable in lower env(except QA). const lpcustomchatQsp = new URLSearchParams(location.search)?.get('lpcustomchat')?.startsWith('true'); if(lpcustomchatQsp) { iFrameInDom.setAttribute("data-iframeSrc", flyoutContainer.getAttribute('data-cep-iframe-url')); } let targetSettings = window.targetGlobalSettings; let cepEnabled = flyoutContainer.getAttribute('data-cep-enabled'); if (cepEnabled === 'true' && targetSettings && targetGlobalSettings.serverState && targetSettings.serverState.response && targetSettings.serverState.response.execute && targetSettings.serverState.response.execute.pageLoad && targetSettings.serverState.response.execute.pageLoad.options) { targetSettings.serverState.response.execute.pageLoad.options.forEach(option => { if (option.responseTokens && option.responseTokens['experience.name'] === '24142t1') { iFrameInDom.setAttribute("data-iframeSrc", flyoutContainer.getAttribute('data-cep-iframe-url')); } }); } } function LPCookieConsent() { $('body').attr(lpInitializeAttrName, 'false'); waitForWcpConsentObj().then(function(){ var wcpConsent = window.WcpConsent; if (wcpConsent) { // pass wcpConsent.siteConsent.isConsentRequired loadLivePersonIFrame(wcpConsent.siteConsent.isConsentRequired); } }); } function loadLivePersonIFrame(isConsentRequired) { $('body').attr(lpConsentRequiredAttrName, isConsentRequired); } /* Function to try to find WcpConsent object */ function waitForWcpConsentObj() { var maxRetryCt = 100; var waitTime = 50; return new Promise(function (resolve, reject) { var retryCt = 0; var intervalHandle = setInterval(function () { // Trying to find wcp object if (retryCt < maxRetryCt) { if (typeof WcpConsent !== 'undefined' && WcpConsent && typeof WcpConsent.siteConsent !== 'undefined' && WcpConsent.siteConsent) { clearInterval(intervalHandle); resolve(); } else { retryCt++; } } else { // Giving up trying to find wcpConsent object clearInterval(intervalHandle); reject(); } }, waitTime); }); } function resizeHandler(event) { sendParentSizeMessage(); } function postMessage(data) { iFrameInDom.contentWindow.postMessage(data, targetDomain); } function sendLpCurrentPageNameAndUrl() { findIFrameElements(); if ($('body').attr(lpConsentRequiredAttrName) === 'false' && $('body').attr(lpInitializeAttrName) === 'false') { postMessage({ action: 'initializeLP' }); $('body').attr(lpInitializeAttrName, 'true'); } // TESTURL: http://approjects.co.za/?big=en-sg/p/surface-book-3/8XBW9G3Z71F1?icid=mscom_marcom&activetab=pivot%3aoverviewtab iFrameInDom.setAttribute('data-lpcurl', window.location.href); // Don't send lpppagename if oneDs is not used postMessage({ lpcurl: window.location.href }); } function sendProactiveInviteMessage(messageName) { findIFrameElements(); postMessage({ invite: messageName }); } function sendTopicMessage() { findIFrameElements(); if (!topicName) { topicName = iFrameInDom.getAttribute('data-isOfficeCommercial').toLowerCase() === 'true' ? 'Office365' : 'Store'; if (iFrameInDom.getAttribute('data-topicName') && iFrameInDom.getAttribute('data-topicName') !== "") { topicName = iFrameInDom.getAttribute('data-topicName'); } } postMessage({ action: 'Topic', Topic: topicName }); } function sendParentSizeMessage() { findIFrameElements(); // This is needed mainly for mobile browsers so that LP can adjust its size based on the parent window dimensions. postMessage({ action: 'parentsize', Width: window.innerWidth, Height: window.innerHeight }); } function sendParentSizeMessageInMobileCanvasOnly() { findIFrameElements(); if (iFrameInDom) { var isMobile = iFrameInDom.getAttribute('data-isMobile').toLowerCase() === 'true'; if (isMobile) { sendParentSizeMessage(); } } } function updateViewPortMetaTagInMobileCanvas() { findIFrameElements(); if (iFrameInDom) { var isMobile = iFrameInDom.getAttribute('data-isMobile').toLowerCase() === 'true'; // update the viewport metatag to get iphone device work for iframe based liveperson as the screen on mobile devices like iphone is getting zoomed out // when the virtual keyboard shows up. The viewport metatag is hardcoded in platform and so making the change in onestore so the fix is // only scoped to onestore and does not effect other partners. if (isMobile) { $('meta[name=viewport]').attr('content', 'width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no'); } } } function keyUpHandler(event) { // Check for Tab keycode and find the last element in footer, when tab focus is on last element set the flag and next tab will move the focus to iframe. if (event.keyCode === 9) { var lastElement = $('#uhf-footer a').last(); if (isFocusSet) { if (!iFrameInDom) { iFrameInDom = document.getElementById(iFrameWindowIDSelector); } iFrameInDom.focus(); isFocusSet = false; } else if (lastElement.text() === document.activeElement.text) { isFocusSet = true; } } } function receiveMessage(event) { /* NOTE: these comments are stripped by the minifier messaging sequence for proactive chat: pageload: ready (unhandled, signifies iFrame ready to send/receive messages) buttonReady displayed - show chat popup modal chatnow click: hide chat popup modal (doesnt wait for message) opened maximized (12 times) */ findIFrameElements(); if (event.origin === targetDomain && event && event.data) { var src = event.data.action || event.data.window || event.data.engagement || event.data.button || event.data.invite; console.log("LP message received: " + src); switch (src) { case 'maximized': updateChatWindowSize(event.data); changeIFrameAttributesInMobile("True","dialog"); break; case 'loading': case 'minimized': updateChatWindowSize(event.data); chatButton.setAttribute("aria-expanded", "true"); changeIFrameAttributesInMobile("False",""); break; case 'opened': showChatWindow(); break; case 'displayed': showProactiveChatInvite(); break; case 'buttonReady': sendParentSizeMessage(); sendLpCurrentPageNameAndUrl(); updateViewPortMetaTagInMobileCanvas(); changeIFrameAttributesInMobile("False",""); break; case 'closed': closeSandBoxFlyout(); break; case 'failed': console.log(event.data.msg); break; default: break; } } } function setChatWindowVisibility(show) { var boolString = (!show).toString(); document.querySelector('#lp-proactive-invite').setAttribute("aria-hidden", boolString); } function showProactiveChatInvite() { // var proactiveInviteButton = $(proactiveChatButtonSelector); // proactiveInviteButton.click(); setChatWindowVisibility(true); var chatNowButton = $(proactiveChatNowSelector); if (chatNowButton) { setTimeout(function () { previouslyFocusedElement = document.activeElement; chatNowButton.focus(); if (previouslyFocusedElement) { document.body.addEventListener("keydown", proactiveChatInviteKeyDownHandler, false); } }, 200); } } function proactiveChatInviteKeyDownHandler(event) { // Go back to the previous focused element if the user uses tab on the "No thanks" button or shift + tab on the "Chat Now" button if ((!event.shiftKey && event.keyCode === 9 && document.activeElement.classList.contains(proactiveNoThanksSelector.replace('.', ''))) || (event.shiftKey && event.keyCode === 9 && document.activeElement.classList.contains(proactiveChatNowSelector.replace('.', '')))) { previouslyFocusedElement.focus(); document.body.removeEventListener("keydown", proactiveChatInviteKeyDownHandler); event.preventDefault(); } } function showChatWindow() { // var chatButton = $(chatButtonSelector); // if (chatButton) { // chatButton.trigger('click', { IsFakeClick: true }); // } setChatWindowVisibility(false); // hide popup flyoutContainer.setAttribute(ariaHiddenAttrName, 'false');// show iframe container sendParentSizeMessageInMobileCanvasOnly(); } function changeIFrameAttributesInMobile(ariaModal, roleValue) { var isMobile = false; isMobile = mwf.Util.detectMobile(false); if (isMobile) { document.querySelector("#LivePerson").setAttribute('aria-modal', ariaModal); document.querySelector("#LivePerson").setAttribute('role', roleValue); } } function updateChatWindowSize(data) { findIFrameElements(); let isMobile = mwf.Util.detectMobile(false); let height = data && data.height ? data.height : ''; let width = isMobile ? (data && data.width ? data.width : '') : (data && data.width ? Math.min(+data.width.replace('px', ''), document.body.clientWidth) + 'px' : ''); if (flyoutContainer && $('.lp-iframe-window')) { $(flyoutContainer).css('height', ('{0}').replace('{0}', height)); $(flyoutContainer).css('min-width', ('{0}').replace('{0}', width)); $(flyoutContainer).css('max-width', ('{0}').replace('{0}', width)); $('.lp-iframe-window').css('height', ('{0}').replace('{0}', height)); $('.lp-iframe-window').css('width', ('{0}').replace('{0}', width)); } } function closeSandBoxFlyout() { //var closeFlyout = $('.lp-iframe-close'); commenting to resolve #6743742 changeIFrameAttributesInMobile("False","") //closeFlyout.click(); commenting to resolve #6743742 if (!flyoutContainer) { flyoutContainer = document.getElementById(flyoutContainerIdSelector); } flyoutContainer.setAttribute(ariaHiddenAttrName, 'true'); chatButton.setAttribute("aria-expanded", "false"); chatButton.focus(); } function setIsMobile() { findIFrameElements(); var isMobile = false; if (iFrameInDom) { isMobile = mwf.Util.detectMobile(false); iFrameInDom.setAttribute('data-isMobile', isMobile ? "True" : "False"); } if (isMobile) { $('#lp-iframe-container').addClass('lp-iframe-mobile'); } } }); } (function() { "use strict"; $(function() { let ctaChatLink = $('.ctaChatLink'); if( (ctaChatLink!=null) && (ctaChatLink.length) ){ $('.multiflyout-hideTextChat').css('display','none'); } }); }());