1/** 2 * header-cookies.js 3 * 4 * Custom cookie consent banner used by the header's Cookies.cshtml 5 * partial. Distinct from the ASP.NET framework banner in 6 * _CookieConsentPartial.cshtml â this one wires Microsoft UET 7 * (window.uetq) ad-storage consent and persists per-storefront state in 8 * a "consent<STORE_FRONT_ID>" cookie. 9 * 10 * Helpers: 11 * - domReady(fn): runs fn on DOMContentLoaded (or immediately if the 12 * DOM is already past loading). 13 * - setCookie(name, value, days): writes a cookie with optional expiry. 14 * 15 * On DOM ready: inspects the consent cookie and either grants or denies 16 * UET ad_storage, then shows or hides the .cookieConsent banner. 17 * 18 * NOTE: acceptCookies and denyCookies MUST remain top-level (global) 19 * functions. The banner's buttons in Cookies.cshtml no longer use inline 20 * onclick attributes (migrated to data-action + delegated listeners in 21 * csp-actions.js for CSP hardening â see docs/csp-hardening-plan.md), but 22 * that dispatcher still invokes these as globals. Do not wrap this file in 23 * an IIFE. 24 * 25 * Depends on $sfConfigModel being defined before this file runs (set by 26 * the layout files' inline script that injects STORE_FRONT_ID, etc.). 27 * Same ordering constraint as the inline block this replaced. 28 * 29 * Extracted verbatim from the inline <script> block; no logic change. 30 */ 31 32 33function domReady(fn) { 34 document.addEventListener("DOMContentLoaded", fn); 35 if (document.readyState === "interactive" || document.readyState === "complete") { 36 fn(); 37 } 38} 39 40function setCookie(name, value, days) { 41 var expires = ""; 42 if (days) { 43 var date = new Date(); 44 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 45 expires = "; expires=" + date.toUTCString(); 46 } 47 document.cookie = name + "=" + (value || "") + expires + "; path=/"; 48} 49 50// domReady(() => { 51// if (document.cookie.indexOf("consent" + $sfConfigModel.STORE_FRONT_ID) > -1) { 52// document.getElementsByClassName("cookieConsent")[0].style.display = "none"; 53// } else { 54// document.getElementsByClassName("cookieConsent")[0].style.display = "block"; 55// } 56// }); 57// domReady(() => { 58 59domReady(() => 60{ 61 window.uetq = window.uetq || []; 62 if (document.cookie.indexOf("consent" + $sfConfigModel.STORE_FRONT_ID) > -1) 63 { 64 window.uetq.push('consent', 'update', { 65 'ad_storage': 'granted' 66 }); 67 document.getElementsByClassName("cookieConsent")[0].style.display = "none"; 68 } 69 else 70 { 71 window.uetq.push('consent', 'update', { 72 'ad_storage': 'denied' 73 }); 74 document.getElementsByClassName("cookieConsent")[0].style.display = "block"; 75 } 76}); 77 78 79function acceptCookies() 80{ 81 setCookie("consent" + $sfConfigModel.STORE_FRONT_ID, "true", 30); 82 83 window.uetq = window.uetq || []; 84 window.uetq.push('consent', 'update', { 85 'ad_storage': 'granted' 86 }); 87 document.getElementsByClassName("cookieConsent")[0].style.display = "none"; 88} 89function denyCookies() 90{ 91 setCookie("consent" + $sfConfigModel.STORE_FRONT_ID, "false", 30); 92 window.uetq = window.uetq || []; 93 window.uetq.push('consent', 'update', { 94 'ad_storage': 'denied' 95 }); 96 document.getElementsByClassName("cookieConsent")[0].style.display = "none"; 97}
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.