1import {CookieUtils} from 'sites/cookie_utils' 2import {PageInitUtils} from 'sites/page_init_utils' 3import {ExplicitConsentModalLauncher} from 'sites/explicit_consent_modal_launcher' 4import {ImpliedConsentLauncher} from "sites/implied_consent_launcher" 5 6export class PageInitialisation { 7 static bind() { 8 this.dynamicallyAddStimulusControllersToBodyElement() 9 document.dispatchEvent(new CustomEvent('clinch:document_ready')) 10 this.findCookieConsentRequiredViaAjax(); 11 } 12 13 14//The body element is specified in the page layout - we don't control it, hence dynamically specifying controllers 15 static dynamicallyAddStimulusControllersToBodyElement() { 16 document.body.dataset.controller = 'tracking kiosk candidate--populator manage-cookies-link-reloader' 17 } 18 19//cannot test this :( 20 static findCookieConsentRequiredViaAjax() { 21 if (js_vars.links) { 22 fetch(js_vars.links.consent.url, {method: js_vars.links.consent.method}) 23 .then(response => response.json()) 24 .then((data) => this.initialize(data.cookie_consent_strategy, data.permanent_cookie_expiry_in_months)) 25 } 26 } 27 28 static initialize(cookieConsentStrategy, permanentCookieExpiryInMonths) { 29 if (cookieConsentStrategy === 'explicit_consent' && CookieUtils.noCookiesAndTrackingActive()) { 30 ExplicitConsentModalLauncher.launchConsentModal() 31 } else { 32 if (CookieUtils.noCookiesAndTrackingActive()) { 33 CookieUtils.generateCookies(permanentCookieExpiryInMonths) 34 } 35 this.checkCookiesAndFire(permanentCookieExpiryInMonths, cookieConsentStrategy); 36 } 37 } 38 39 static checkCookiesAndFire(permanentCookieExpiryInMonths, cookieConsentStrategy) { 40 if (CookieUtils.trackingCookie()) { 41 this.migrateCookieIfActive(permanentCookieExpiryInMonths) 42 this.regenerateTrackingSessionCookieIfGone() 43 44 if (this.shouldOpenImplicitConsent(cookieConsentStrategy)) { 45 PageInitUtils.fireTrackable({detail: {consent_accepted: true}}) 46 ImpliedConsentLauncher.openImplicitConsentOffCanvas() 47 } else { 48 PageInitUtils.fireTrackable() 49 } 50 } 51 } 52 53 static shouldOpenImplicitConsent(cookieConsentStrategy) { 54 return cookieConsentStrategy === 'implicit_consent' && !CookieUtils.clinchImpliedConsentFooterHiddenCookie() 55 } 56 57 static migrateCookieIfActive(permanentCookieExpiryInMonths) { 58 if (js_vars.migrate_cookie.active) { 59 CookieUtils.migrateCookie('ctc', js_vars.migrate_cookie.from_domain, permanentCookieExpiryInMonths) 60 } 61 } 62 63 static regenerateTrackingSessionCookieIfGone() { 64 if (!CookieUtils.trackingSessionCookie()) 65 CookieUtils.setTrackingSessionCookie(); 66 } 67}
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.