window.openConsentModal = (function() {
const flags = {
advertising1st: {current: 'c11'},
advertising3rd: {current: 'c3', legacy: 'c7'},
attribution3rd: {current: 'c12'},
analytics1st: {current: 'c10'},
analytics3rd: {current: 'c2', legacy: 'c8'},
preference: {current: 'c6'},
performance: {current: 'c9'}
}
const setImplicitBit = (inValue, n, v) => {
if (v) {
return inValue | 1 << n;
}
else {
return inValue & ~(1 << n);
}
}
const getOPTOUTCookie = () => {
let opt = {};
let optCookie = ui.getCookie("OPTOUTMULTI");
if (!optCookie) {
opt = isEu ?
{
'0':'1',
'c1':'1',
'c3':'1',
'c7':'1',
'c12':'1',
'c11':'1',
'c2':'1',
'c8':'1',
'c10':'1',
'c6':'1',
'c9':'1',
'i':'8140'
} : {
'0':'0',
'c1':'0',
'c3':'0',
'c7':'0',
'c12':'0',
'c11':'0',
'c2':'0',
'c8':'0',
'c10':'0',
'c6':'0',
'c9':'0',
'i':'8140'
}
return opt;
}
decodeURIComponent(optCookie).split('|').forEach(el => {
let [key, value] = el.split(':');
opt[key] = value;
});
return opt;
}
const saveOPTOUTCookie = (obj) => {
let arr = [];
Object.entries(obj).forEach(item => {
arr.push(item.join(':'));
});
let output = encodeURI(arr.join('|'));
ui.setCookie("OPTOUTMULTI", output, 183);
}
const loadData = () => {
fetch('/api/privacy/consent-info')
.then(response => response.json())
.then(data => setData(data))
.catch(err => console.error(err));
}
const setData = (data) => {
let consents = [];
consents = data.consents;
consents.forEach(consent => {
let isSwitch = false;
let currentFlags = [];
Object.keys(data.controlFlagDefaults).forEach(key => {
if (data.controlFlagDefaults[key].consent === consent.id) {
isSwitch = true;
currentFlags.push(flags[key].current);
if ((data.consentPolicyId === 'targeted-ads' || data.consentPolicyId === 'cpra') && flags[key].legacy) {
currentFlags.push(flags[key].legacy);
}
}
})
if (isSwitch) {
consent.switch = consent.id;
consent.flags = currentFlags;
} else {
consent.switch = null;
}
})
addModal(data, consents);
}
const addModal = (data, consents) => {
const switchWasPresent = ui.switch;
let title = ``;
let switchIds = [];
let optout = getOPTOUTCookie();
let subtitle = `${data.description}`;
let content = `
${subtitle}
`;
content += '';
let doHr = false;
consents.forEach(consent => {
if (consent.switch === 'advertising-sell-share' && undefined) {
content += '
';
doHr = true;
} else if (doHr) {
content += '
';
doHr = false;
} else {
content += '
';
}
content += `
${consent.label}
`;
content += `
${consent.description}
`;
if (consent.switch) {
let id = {domId: `switch-${consent.switch}-toggle`, flags: consent.flags, confirm: consent.confirmation};
switchIds.push(id);
let isChecked = true;
consent.flags.forEach(flag => {
isChecked = isChecked && optout[`${flag}`] === '0';
})
content += `
`;
content += ``
content += "
";
}
if (consent.switch === 'advertising-sell-share' && undefined) {
content += '
';
}
});
content += `
`;
content += "
";
const updateData = (sid, e) => {
if (!optout.hasOwnProperty('i')) optout.i = 8140;
sid.flags.forEach(flag => {
optout[`${flag}`] = e.target.checked ? '0' : '1';
optout.i = setImplicitBit(optout.i, flag.substring(1), 0);
});
saveOPTOUTCookie(optout);
document.body.dispatchEvent(new CustomEvent("consentupdated"));
}
let isFirstOpen = true;
let modal = ui.modal(`${title}${content}
`, {
closeOnBkgClick: false,
hideCloseBtn: true,
onOpen: () => {
if (isFirstOpen) {
ui.switch('#consent-modal .switch');
switchIds.forEach(sid => {
document.getElementById(sid.domId).addEventListener('change', (e) => {
if (sid.confirm && e.target.checked) {
if (document.querySelector('.pulseDiv')) document.querySelector('.pulseDiv').style.animation = 'none';
let confirmModal = ui.modal(`${sid.confirm.description}
`, {
closeOnBkgClick: false,
hideCloseBtn: true,
onOpen: () => {
document.getElementById('confirm-modal-close-yes').addEventListener('click', () => {
confirmModal.close();
updateData(sid, e);
modal.open();
});
document.getElementById('confirm-modal-close-no').addEventListener('click', () => {
confirmModal.close();
e.target.checked = false;
modal.open();
});
}
});
confirmModal.open();
} else if (sid.confirm && !e.target.checked) {
if (window.unifiedTrackingFactory) {
var instance = window.unifiedTrackingFactory();
instance.trackUserBehavior("CoreUI_ConsentChanged", { type: "ccpa-sell-share", action: "optOut", unifiedEvent: true });
}
updateData(sid, e);
} else {
updateData(sid, e);
}
});
});
document.getElementById('privacy-modal-close').addEventListener('click', () => {modal.close()});
isFirstOpen = false;
}
modal.resize('95%');
if (document.querySelector('#sellShareScrollTarget')) {
document.querySelector('#sellShareScrollTarget').scrollIntoView();
}
}
});
if (!switchWasPresent) {
let src = document.querySelector("script[src$='/js/core.js']").src.replace('core', 'switch');
let script = document.createElement("SCRIPT");
script.setAttribute("src", src);
script.setAttribute("defer", "");
document.head.appendChild(script);
script.addEventListener('load', e => {
modal.open();
})
} else {
modal.open();
}
if (!document.querySelector("link[href$='/css/switch.css'][rel=stylesheet]")) {
let src = document.querySelector("script[src$='/js/switch.js']").src.replaceAll('js','css');
let link = document.createElement("LINK");
link.setAttribute("rel", "stylesheet");
link.setAttribute("href", src);
document.head.appendChild(link);
}
}
return loadData;
})();
{
//This code is specifically for the legal page /c/legal/aboutcookies
//This is about the only way for the button to function unless an event listener is added by the page itself
const target = document.body;
let iter = 0;
const run = () => window.openConsentModal();
const config = { childList: true, subtree: true };
const callback = (mutationList) => {
if (iter === 0 || mutationList.length > 20) {
const modalLink = document.querySelector('#consent-modal-open-button');
if (modalLink) {
modalLink.removeEventListener('click', run);
modalLink.addEventListener('click', run);
}
iter++;
}
}
const observer = new MutationObserver(callback);
observer.observe(target, config);
}