|
1 | 1 | /* global GovSingleConsent */ |
2 | 2 |
|
3 | | -;(function () { |
| 3 | +(function () { |
4 | 4 | function CookieBanner($component) { |
5 | | - this.$component = $component |
| 5 | + this.$component = $component; |
6 | 6 | } |
7 | 7 |
|
8 | 8 | CookieBanner.prototype.init = function () { |
9 | | - this.$component.hidden = true |
| 9 | + this.$component.hidden = true; |
10 | 10 |
|
11 | 11 | this.$component.message = this.$component.querySelector( |
12 | | - '.js-cookie-banner-message' |
13 | | - ) |
| 12 | + ".js-cookie-banner-message", |
| 13 | + ); |
14 | 14 | this.$component.confirmAccept = this.$component.querySelector( |
15 | | - '.js-cookie-banner-confirmation-accept' |
16 | | - ) |
| 15 | + ".js-cookie-banner-confirmation-accept", |
| 16 | + ); |
17 | 17 | this.$component.confirmReject = this.$component.querySelector( |
18 | | - '.js-cookie-banner-confirmation-reject' |
19 | | - ) |
| 18 | + ".js-cookie-banner-confirmation-reject", |
| 19 | + ); |
20 | 20 |
|
21 | | - this.$component.setCookieConsent = this.acceptCookies.bind(this) |
| 21 | + this.$component.setCookieConsent = this.acceptCookies.bind(this); |
22 | 22 | this.$component.showAcceptConfirmation = |
23 | | - this.showAcceptConfirmation.bind(this) |
| 23 | + this.showAcceptConfirmation.bind(this); |
24 | 24 | this.$component |
25 | | - .querySelector('[data-accept-cookies]') |
26 | | - .addEventListener('click', this.$component.setCookieConsent) |
27 | | - this.$component.rejectCookieConsent = this.rejectCookies.bind(this) |
| 25 | + .querySelector("[data-accept-cookies]") |
| 26 | + .addEventListener("click", this.$component.setCookieConsent); |
| 27 | + this.$component.rejectCookieConsent = this.rejectCookies.bind(this); |
28 | 28 | this.$component.showRejectConfirmation = |
29 | | - this.showRejectConfirmation.bind(this) |
| 29 | + this.showRejectConfirmation.bind(this); |
30 | 30 | this.$component |
31 | | - .querySelector('[data-reject-cookies]') |
32 | | - .addEventListener('click', this.$component.rejectCookieConsent) |
| 31 | + .querySelector("[data-reject-cookies]") |
| 32 | + .addEventListener("click", this.$component.rejectCookieConsent); |
33 | 33 |
|
34 | 34 | var hideBannerBtnNodes = this.$component.querySelectorAll( |
35 | | - '[data-hide-cookie-message]' |
36 | | - ) |
| 35 | + "[data-hide-cookie-message]", |
| 36 | + ); |
37 | 37 | for (var i = 0, length = hideBannerBtnNodes.length; i < length; i++) { |
38 | 38 | hideBannerBtnNodes[i].addEventListener( |
39 | | - 'click', |
40 | | - this.hideBanner.bind(this) |
41 | | - ) |
| 39 | + "click", |
| 40 | + this.hideBanner.bind(this), |
| 41 | + ); |
42 | 42 | } |
43 | 43 |
|
44 | 44 | function onConsentsUpdated(consents, consentsPreferencesSet, error) { |
45 | 45 | if (consentsPreferencesSet) { |
46 | | - this.hideBanner() |
| 46 | + this.hideBanner(); |
47 | 47 | } else { |
48 | | - this.showBanner() |
| 48 | + this.showBanner(); |
49 | 49 | } |
50 | 50 | if (error) { |
51 | | - console.error(error) |
| 51 | + console.error(error); |
52 | 52 | } |
53 | 53 | } |
54 | 54 |
|
55 | 55 | this.singleConsent = new GovSingleConsent( |
56 | 56 | onConsentsUpdated.bind(this), |
57 | | - window.GovSingleConsentApiBaseURL |
58 | | - ) |
59 | | - } |
| 57 | + window.GovSingleConsentApiBaseURL, |
| 58 | + ); |
| 59 | + }; |
60 | 60 |
|
61 | 61 | CookieBanner.prototype.showBanner = function () { |
62 | 62 | var acceptedAdditionalCookies = |
63 | 63 | GovSingleConsent.hasConsentedToUsage() || |
64 | 64 | GovSingleConsent.hasConsentedToCampaigns() || |
65 | | - GovSingleConsent.hasConsentedToSettings() |
| 65 | + GovSingleConsent.hasConsentedToSettings(); |
66 | 66 |
|
67 | | - this.$component.hidden = false |
| 67 | + this.$component.hidden = false; |
68 | 68 | this.$component.confirmAccept.hidden = |
69 | | - !GovSingleConsent.isConsentPreferencesSet() || !acceptedAdditionalCookies |
| 69 | + !GovSingleConsent.isConsentPreferencesSet() || !acceptedAdditionalCookies; |
70 | 70 | this.$component.confirmReject.hidden = |
71 | | - !GovSingleConsent.isConsentPreferencesSet() || acceptedAdditionalCookies |
72 | | - } |
| 71 | + !GovSingleConsent.isConsentPreferencesSet() || acceptedAdditionalCookies; |
| 72 | + }; |
73 | 73 |
|
74 | 74 | CookieBanner.prototype.hideBanner = function () { |
75 | | - this.$component.hidden = true |
76 | | - } |
| 75 | + this.$component.hidden = true; |
| 76 | + }; |
77 | 77 |
|
78 | 78 | CookieBanner.prototype.acceptCookies = function () { |
79 | | - this.$component.showAcceptConfirmation() |
80 | | - this.singleConsent.setConsents(GovSingleConsent.ACCEPT_ALL) |
81 | | - } |
| 79 | + this.$component.showAcceptConfirmation(); |
| 80 | + this.singleConsent.setConsents(GovSingleConsent.ACCEPT_ALL); |
| 81 | + }; |
82 | 82 |
|
83 | 83 | CookieBanner.prototype.showAcceptConfirmation = function () { |
84 | | - this.$component.message.hidden = true |
85 | | - this.$component.confirmAccept.hidden = false |
86 | | - this.$component.confirmAccept.focus() |
87 | | - } |
| 84 | + this.$component.message.hidden = true; |
| 85 | + this.$component.confirmAccept.hidden = false; |
| 86 | + this.$component.confirmAccept.focus(); |
| 87 | + }; |
88 | 88 |
|
89 | 89 | CookieBanner.prototype.rejectCookies = function () { |
90 | | - this.$component.showRejectConfirmation() |
91 | | - this.singleConsent.setConsents(GovSingleConsent.REJECT_ALL) |
92 | | - } |
| 90 | + this.$component.showRejectConfirmation(); |
| 91 | + this.singleConsent.setConsents(GovSingleConsent.REJECT_ALL); |
| 92 | + }; |
93 | 93 |
|
94 | 94 | CookieBanner.prototype.showRejectConfirmation = function () { |
95 | | - this.$component.message.hidden = true |
96 | | - this.$component.confirmReject.hidden = false |
97 | | - this.$component.confirmReject.focus() |
98 | | - } |
| 95 | + this.$component.message.hidden = true; |
| 96 | + this.$component.confirmReject.hidden = false; |
| 97 | + this.$component.confirmReject.focus(); |
| 98 | + }; |
99 | 99 |
|
100 | | - window.CookieBanner = CookieBanner |
| 100 | + window.CookieBanner = CookieBanner; |
101 | 101 |
|
102 | | - document.addEventListener('DOMContentLoaded', function () { |
| 102 | + document.addEventListener("DOMContentLoaded", function () { |
103 | 103 | var nodes = document.querySelectorAll( |
104 | | - '[data-module~="govuk-cookie-banner"]' |
105 | | - ) |
| 104 | + '[data-module~="govuk-cookie-banner"]', |
| 105 | + ); |
106 | 106 | for (var i = 0, length = nodes.length; i < length; i++) { |
107 | | - new CookieBanner(nodes[i]).init() |
| 107 | + new CookieBanner(nodes[i]).init(); |
108 | 108 | } |
109 | | - }) |
110 | | -})() |
| 109 | + }); |
| 110 | +})(); |
0 commit comments