1import {Controller} from "@hotwired/stimulus" 2import {CookieUtils} from "sites/cookie_utils" 3import {PageInitUtils} from "sites/page_init_utils" 4import {ExplicitConsentModalLauncher} from "sites/explicit_consent_modal_launcher" 5 6export default class extends Controller { 7 static targets = ['allowPerformanceCookies', 'cookieConsentPreferences', 'consentAgreeButton', 'manageConsentButton', 'consentSaveButton', 'consentRejectButton', 'consentContextBanner'] 8 static values = {expires: Number, consentStrategy: String, contextBannerText: String} 9 10 connect() { 11 if (this.shouldManagePreferences()){ 12 this.launchExplicitConsentModalAndShowCookiePreferences() 13 } 14 } 15 16 contextBannerTextValueChanged(value) { 17 this.consentContextBannerTarget.textContent = value 18 if (value) this.element.addEventListener('hidden.bs.modal', () => { this.contextBannerTextValue = '' }, {once: true}) 19 } 20 21 shouldManagePreferences() { 22 return window.location.hash === "#showManageCookiesDialog" && this.hasManageConsentButtonTarget 23 } 24 25 launchExplicitConsentModalAndShowCookiePreferences(){ 26 this.showCookiePreferences() 27 ExplicitConsentModalLauncher.launchConsentModal() 28 } 29 30 saveCookiePreferences() { 31 if (this.allowPerformanceCookiesTarget.checked) { 32 this.acceptCookies() 33 } else { 34 this.rejectCookies() 35 } 36 } 37 38 showCookiePreferences() { 39 this.consentAgreeButtonTarget.style.display = 'none' 40 this.manageConsentButtonTarget.style.display = 'none' 41 if (this.hasConsentRejectButtonTarget) { 42 this.consentRejectButtonTarget.style.display = 'none' 43 } 44 this.consentSaveButtonTarget.style.display = 'block' 45 this.cookieConsentPreferencesTarget.style.display = 'block' 46 this.uncheckAllowPerformanceCookies(); 47 } 48 49 50 acceptCookies() { 51 CookieUtils.generateCookies(this.expiresValue) 52 PageInitUtils.fireTrackable({detail: {consent_accepted: true}}) 53 } 54 55 rejectCookies() { 56 CookieUtils.setTrackingRejectedCookie(this.expiresValue) 57 CookieUtils.removeTrackingCookie() 58 CookieUtils.removeSessionCookie() 59 PageInitUtils.fireUntrackable() 60 } 61 62 // looks at the cookies already set to determine the starting state to show the form. 63 // If CTC exists then the user had previously allowed performance cookies 64 65 uncheckAllowPerformanceCookies() { 66 if (CookieUtils.noCookiesAndTrackingActive() || CookieUtils.noTrackingRejectedCookie()) { 67 this.allowPerformanceCookiesTarget.checked = false 68 this.allowPerformanceCookiesTarget.dispatchEvent(new CustomEvent('change', null)) 69 } 70 } 71}
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.