-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
- Loading branch information
1 parent
b560405
commit 7782825
Showing
6 changed files
with
157 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,110 @@ | ||
/* global GovSingleConsent */ | ||
|
||
;(function () { | ||
(function () { | ||
function CookieBanner($component) { | ||
this.$component = $component | ||
this.$component = $component; | ||
} | ||
|
||
CookieBanner.prototype.init = function () { | ||
this.$component.hidden = true | ||
this.$component.hidden = true; | ||
|
||
this.$component.message = this.$component.querySelector( | ||
'.js-cookie-banner-message' | ||
) | ||
".js-cookie-banner-message", | ||
); | ||
this.$component.confirmAccept = this.$component.querySelector( | ||
'.js-cookie-banner-confirmation-accept' | ||
) | ||
".js-cookie-banner-confirmation-accept", | ||
); | ||
this.$component.confirmReject = this.$component.querySelector( | ||
'.js-cookie-banner-confirmation-reject' | ||
) | ||
".js-cookie-banner-confirmation-reject", | ||
); | ||
|
||
this.$component.setCookieConsent = this.acceptCookies.bind(this) | ||
this.$component.setCookieConsent = this.acceptCookies.bind(this); | ||
this.$component.showAcceptConfirmation = | ||
this.showAcceptConfirmation.bind(this) | ||
this.showAcceptConfirmation.bind(this); | ||
this.$component | ||
.querySelector('[data-accept-cookies]') | ||
.addEventListener('click', this.$component.setCookieConsent) | ||
this.$component.rejectCookieConsent = this.rejectCookies.bind(this) | ||
.querySelector("[data-accept-cookies]") | ||
.addEventListener("click", this.$component.setCookieConsent); | ||
this.$component.rejectCookieConsent = this.rejectCookies.bind(this); | ||
this.$component.showRejectConfirmation = | ||
this.showRejectConfirmation.bind(this) | ||
this.showRejectConfirmation.bind(this); | ||
this.$component | ||
.querySelector('[data-reject-cookies]') | ||
.addEventListener('click', this.$component.rejectCookieConsent) | ||
.querySelector("[data-reject-cookies]") | ||
.addEventListener("click", this.$component.rejectCookieConsent); | ||
|
||
var hideBannerBtnNodes = this.$component.querySelectorAll( | ||
'[data-hide-cookie-message]' | ||
) | ||
"[data-hide-cookie-message]", | ||
); | ||
for (var i = 0, length = hideBannerBtnNodes.length; i < length; i++) { | ||
hideBannerBtnNodes[i].addEventListener( | ||
'click', | ||
this.hideBanner.bind(this) | ||
) | ||
"click", | ||
this.hideBanner.bind(this), | ||
); | ||
} | ||
|
||
function onConsentsUpdated(consents, consentsPreferencesSet, error) { | ||
if (consentsPreferencesSet) { | ||
this.hideBanner() | ||
this.hideBanner(); | ||
} else { | ||
this.showBanner() | ||
this.showBanner(); | ||
} | ||
if (error) { | ||
console.error(error) | ||
console.error(error); | ||
} | ||
} | ||
|
||
this.singleConsent = new GovSingleConsent( | ||
onConsentsUpdated.bind(this), | ||
window.GovSingleConsentApiURL | ||
) | ||
} | ||
window.GovSingleConsentApiURL, | ||
); | ||
}; | ||
|
||
CookieBanner.prototype.showBanner = function () { | ||
var acceptedAdditionalCookies = | ||
GovSingleConsent.hasConsentedToUsage() || | ||
GovSingleConsent.hasConsentedToCampaigns() || | ||
GovSingleConsent.hasConsentedToSettings() | ||
GovSingleConsent.hasConsentedToSettings(); | ||
|
||
this.$component.hidden = false | ||
this.$component.hidden = false; | ||
this.$component.confirmAccept.hidden = | ||
!GovSingleConsent.isConsentPreferencesSet() || !acceptedAdditionalCookies | ||
!GovSingleConsent.isConsentPreferencesSet() || !acceptedAdditionalCookies; | ||
this.$component.confirmReject.hidden = | ||
!GovSingleConsent.isConsentPreferencesSet() || acceptedAdditionalCookies | ||
} | ||
!GovSingleConsent.isConsentPreferencesSet() || acceptedAdditionalCookies; | ||
}; | ||
|
||
CookieBanner.prototype.hideBanner = function () { | ||
this.$component.hidden = true | ||
} | ||
this.$component.hidden = true; | ||
}; | ||
|
||
CookieBanner.prototype.acceptCookies = function () { | ||
this.$component.showAcceptConfirmation() | ||
this.singleConsent.setConsents(GovSingleConsent.ACCEPT_ALL) | ||
} | ||
this.$component.showAcceptConfirmation(); | ||
this.singleConsent.setConsents(GovSingleConsent.ACCEPT_ALL); | ||
}; | ||
|
||
CookieBanner.prototype.showAcceptConfirmation = function () { | ||
this.$component.message.hidden = true | ||
this.$component.confirmAccept.hidden = false | ||
this.$component.confirmAccept.focus() | ||
} | ||
this.$component.message.hidden = true; | ||
this.$component.confirmAccept.hidden = false; | ||
this.$component.confirmAccept.focus(); | ||
}; | ||
|
||
CookieBanner.prototype.rejectCookies = function () { | ||
this.$component.showRejectConfirmation() | ||
this.singleConsent.setConsents(GovSingleConsent.REJECT_ALL) | ||
} | ||
this.$component.showRejectConfirmation(); | ||
this.singleConsent.setConsents(GovSingleConsent.REJECT_ALL); | ||
}; | ||
|
||
CookieBanner.prototype.showRejectConfirmation = function () { | ||
this.$component.message.hidden = true | ||
this.$component.confirmReject.hidden = false | ||
this.$component.confirmReject.focus() | ||
} | ||
this.$component.message.hidden = true; | ||
this.$component.confirmReject.hidden = false; | ||
this.$component.confirmReject.focus(); | ||
}; | ||
|
||
window.CookieBanner = CookieBanner | ||
window.CookieBanner = CookieBanner; | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
document.addEventListener("DOMContentLoaded", function () { | ||
var nodes = document.querySelectorAll( | ||
'[data-module~="govuk-cookie-banner"]' | ||
) | ||
'[data-module~="govuk-cookie-banner"]', | ||
); | ||
for (var i = 0, length = nodes.length; i < length; i++) { | ||
new CookieBanner(nodes[i]).init() | ||
new CookieBanner(nodes[i]).init(); | ||
} | ||
}) | ||
})() | ||
}); | ||
})(); |
Oops, something went wrong.