Skip to content

Commit

Permalink
WIP cookie banner
Browse files Browse the repository at this point in the history
  • Loading branch information
andysellick committed Feb 7, 2024
1 parent 487429f commit a2b5eaf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
//= require ./analytics-ga4/ga4-scroll-tracker
//= require ./analytics-ga4/ga4-video-tracker
//= require ./analytics-ga4/init-ga4
// window.GOVUK.useSingleConsentApi = true // FIXME temporary, need to set this in static
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
this.$module.setCookieConsent = this.setCookieConsent.bind(this)
this.$module.rejectCookieConsent = this.rejectCookieConsent.bind(this)
this.setupCookieMessage()
// window.addEventListener('cookie-consent', this.$module.hideCookieMessage)
window.GOVUK.singleConsent.init()
}

CookieBanner.prototype.setupCookieMessage = function () {
Expand Down Expand Up @@ -47,7 +49,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};

// Set the default consent cookie if it isn't already present
if (!window.GOVUK.cookie('cookies_policy')) {
window.GOVUK.setDefaultConsentCookie()
// window.GOVUK.setDefaultConsentCookie()
window.GOVUK.singleConsent.init(false, window.GOVUK.setDefaultConsentCookie())
}

window.GOVUK.deleteUnconsentedCookies()
Expand All @@ -56,9 +59,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
}

CookieBanner.prototype.hideCookieMessage = function (event) {
window.removeEventListener('cookie-consent', this.$module.hideCookieMessage)
if (this.$module) {
this.$module.hidden = true
window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
// window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
window.GOVUK.singleConsent.init(false, window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 }))
}

if (event.target) {
Expand All @@ -70,25 +75,31 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
if (this.$acceptCookiesButton.getAttribute('data-cookie-types') === 'all') {
this.$module.querySelector('.gem-c-cookie-banner__confirmation-message--accepted').hidden = false
}
window.GOVUK.approveAllCookieTypes()
// window.GOVUK.approveAllCookieTypes()
window.GOVUK.singleConsent.init(false, window.GOVUK.approveAllCookieTypes())
this.$module.showConfirmationMessage()
this.$module.cookieBannerConfirmationMessage.focus()
window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
// window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
window.GOVUK.singleConsent.init(window.GOVUK.singleConsent.setPreferences.bind(null, 'accept'), window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 }))

if (window.GOVUK.analyticsInit) {
window.GOVUK.analyticsInit()
}
if (window.GOVUK.globalBarInit) {
window.GOVUK.globalBarInit.init()
}
window.GOVUK.triggerEvent(window, 'cookie-consent')
// window.GOVUK.triggerEvent(window, 'cookie-consent')
window.GOVUK.singleConsent.init(false, window.GOVUK.triggerEvent(window, 'cookie-consent'))
}

CookieBanner.prototype.rejectCookieConsent = function () {
this.$module.querySelector('.gem-c-cookie-banner__confirmation-message--rejected').hidden = false
this.$module.showConfirmationMessage()
this.$module.cookieBannerConfirmationMessage.focus()
window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
window.GOVUK.setDefaultConsentCookie()
// window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
window.GOVUK.singleConsent.init(false, window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 }))
// window.GOVUK.setDefaultConsentCookie()
window.GOVUK.singleConsent.init(false, window.GOVUK.setDefaultConsentCookie())
}

CookieBanner.prototype.showConfirmationMessage = function () {
Expand Down

0 comments on commit a2b5eaf

Please sign in to comment.