//Load visualforce page to get global variables. This does not work in preview or builder mode in sandbox or production const vfPage = "/apex/pexHeadMarkupVariables"; let vfPageUrl; const hostname = document.location.hostname; if (hostname.includes('my.site') && hostname.includes('chs1')) { //Use salesforce standard domain and path vfPageUrl = 'https://' + hostname + '/producercenter' + vfPage; } else { //Use custom domain vfPageUrl = 'https://' + hostname + vfPage; } let globalVariables; var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { globalVariables = JSON.parse(xmlhttp.responseText); } } xmlhttp.open("GET", vfPageUrl, false); xmlhttp.send(); console.log('globalVariables from VF', JSON.stringify(globalVariables)); //set as exportable variable for script elements to utilize window.globalVariables = globalVariables; //sets username in portal_id propert for mixpanel var utag_data = { "portal_id": globalVariables?.username }; console.log('utag_data', JSON.stringify(utag_data)); //Load TealiumIQ scripts for Mixpanel tracking function loadTealiumIq() { //if url contains ppmo (for preview/buildermode) or sandbox name is PPMO use 'qa'. if sandbox is false use prod, otherwise default to dev const isSandbox = document.location.hostname.indexOf('.sandbox') !== -1 || globalVariables?.IsSandbox === 'true' ? true : false; const isPPMO = document.location.hostname.indexOf('ppmo') !== -1 || globalVariables?.SandboxName === 'ppmo' var tl_environment = isPPMO ? 'qa' : isSandbox === false ? 'prod' : 'dev'; console.log('tl_environment ' + tl_environment); (function (a, b, c, d) { a = '//tags.tiqcdn.com/utag/cambia/main/' + tl_environment + '/utag.js'; b = document; c = 'script'; d = b.createElement(c); d.src = a; d.type = 'text/java' + c; d.async = true; a = b.getElementsByTagName(c)[0]; a.parentNode.insertBefore(d, a); })(); window.addEventListener("utagLink", function (event) { let linkData = event.detail; linkData.event_name = 'link_click'; utag.link(linkData); }); window.addEventListener("utagView", function (event) { utag.view(event.detail); }); } //Load sheetjs static resource function loadSheetJs() { //Hard code url to Production when in preview/builder mode, otherwise relative URL works var sheetJsStaticResourceUrl = globalVariables?.SheetJsUrl ? globalVariables?.SheetJsUrl : 'https://chs1.my.site.com/producercenter/resource/sheetjs'; console.log('sheetJsStaticResourceUrl', sheetJsStaticResourceUrl); (function (a, b, c, d) { a = sheetJsStaticResourceUrl; b = document; c = 'script'; d = b.createElement(c); d.src = a; d.type = 'text/java' + c; d.async = true; a = b.getElementsByTagName(c)[0]; a.parentNode.insertBefore(d, a); })(); window.addEventListener("downloadXLSX", function (event) { try { const data = event?.detail?.data?.length ? event.detail.data : []; console.log('downloadXLSX data ' + JSON.stringify(data)); const fileName = event?.detail?.fileName ? event.detail.fileName : 'export'; console.log('downloadXLSX fileName ' + JSON.stringify(fileName)); const sheetName = event?.detail?.sheetName ? event.detail.sheetName : null; console.log('downloadXLSX sheetName ' + JSON.stringify(sheetName)); const options = event?.detail?.options ? event.detail.options : {}; console.log('downloadXLSX options ' + JSON.stringify(options)); var wb = XLSX.utils.book_new(); var ws = XLSX.utils.json_to_sheet(data, options); if (event?.detail?.columnWidths?.length) { ws["!cols"] = event.detail.columnWidths; } XLSX.utils.book_append_sheet(wb, ws, sheetName); XLSX.writeFile(wb, fileName + ".xlsx"); dispatchEvent( new CustomEvent( 'downloadXLSXComplete', { detail: { status: 'Success', } } ) ); } catch (err) { console.log('downloadXLSX error ' + err); dispatchEvent( new CustomEvent( 'downloadXLSXComplete', { detail: { status: 'Error', message: err } } ) ); } }); } setTimeout( function () { loadTealiumIq(); loadSheetJs(); }, 500 ); //function that sets height and width as global css variables const handleResize = () => { console.log('handleResize width ' + window.innerWidth); console.log('handleResize height ' + window.innerHeight); document.querySelector(':root').style.setProperty('--windowWidth', window.innerWidth + 'px'); document.querySelector(':root').style.setProperty('--windowHeight', window.innerHeight + 'px'); } //call function to set on initial load handleResize(); //add a resize event listener so width and height are continually set as user resizes window window.addEventListener("resize", handleResize);