1/** 2 * Bootstrap for the vxcookies standalone bundle (shared across VX layout PFMs). 3 * Bundle is built in the sibling vxcookies repo into ./dist/vxcookies.js (not npm). 4 * Expects window.__VXCOOKIES_CONFIG__ to be set before this script runs. 5 * 6 * In Smarty: ##layout.vxcookies.vxcookies-bootstrap.js## 7 * (served as /static/vx/<pfm>/vxcookies/vxcookies-bootstrap.js via symlink per PFM). 8 */ 9if (typeof globalThis.process === 'undefined') { 10 globalThis.process = { env: {} }; 11} 12if (typeof globalThis.process.env === 'undefined') { 13 globalThis.process.env = {}; 14} 15// Standalone bundle picks react.production vs development from this at load time; force production. 16globalThis.process.env.NODE_ENV = 'production'; 17 18const config = window.__VXCOOKIES_CONFIG__; 19if (!config) { 20 console.warn('[vxcookies] window.__VXCOOKIES_CONFIG__ not set'); 21} else { 22 function enableScriptsForCategories(acceptedCategories) { 23 if (!acceptedCategories || !acceptedCategories.length) return; 24 const scripts = document.querySelectorAll('script[data-cookiecategory]'); 25 scripts.forEach((script) => { 26 const category = script.getAttribute('data-cookiecategory'); 27 if (acceptedCategories.indexOf(category) === -1) return; 28 if (script.getAttribute('data-vxcookies-done') === '1') return; 29 script.setAttribute('data-vxcookies-done', '1'); 30 const src = script.getAttribute('src'); 31 if (src) { 32 const newScript = document.createElement('script'); 33 newScript.src = src; 34 newScript.defer = script.defer; 35 newScript.async = script.async; 36 script.parentNode.insertBefore(newScript, script.nextSibling); 37 } else { 38 const code = script.textContent; 39 if (code) { 40 const exec = document.createElement('script'); 41 exec.type = 'text/javascript'; 42 exec.textContent = code; 43 script.parentNode.insertBefore(exec, script.nextSibling); 44 } 45 } 46 }); 47 } 48 49 const onFirstAccept = config.onFirstAccept; 50 const onPreferencesChange = config.onPreferencesChange; 51 52 config.onFirstAccept = function (data) { 53 if (data && data.accepted_categories) { 54 enableScriptsForCategories(data.accepted_categories); 55 } 56 if (onFirstAccept) onFirstAccept(data); 57 }; 58 59 config.onPreferencesChange = function (consent, changedCategories) { 60 const accepted = consent && consent.accepted_categories ? consent.accepted_categories : []; 61 enableScriptsForCategories(accepted); 62 if (onPreferencesChange) onPreferencesChange(consent, changedCategories); 63 }; 64 65 /* 66 * vxcookies - internal shared library 67 * bundled directly into this project (dist/vxcookies.js) 68 * repo: https://github.com/Campoint/vxcookies 69 */ 70 const bundleVer = new URL(import.meta.url).searchParams.get('ver'); 71 const bundleUrl = bundleVer ? `./dist/vxcookies.js?ver=${bundleVer}` : './dist/vxcookies.js'; 72 73 function run() { 74 import(bundleUrl) 75 .then((m) => { 76 const vxcookies = m.default || m; 77 vxcookies.init(config); 78 }) 79 .catch((err) => { 80 console.error('[vxcookies] Failed to load vxcookies.js', err); 81 }); 82 } 83 84 if (document.body) { 85 run(); 86 } else { 87 document.addEventListener('DOMContentLoaded', run); 88 } 89}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.