Skip to content

Commit cf68026

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ec8774c commit cf68026

File tree

14 files changed

+165
-160
lines changed

14 files changed

+165
-160
lines changed

client/.eslintrc.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ module.exports = {
44
es2021: false,
55
node: true,
66
},
7-
extends: 'eslint:recommended',
7+
extends: "eslint:recommended",
88
overrides: [],
99
parserOptions: {
1010
ecmaVersion: 2020,
11-
sourceType: 'module',
12-
project: 'tsconfig.json',
11+
sourceType: "module",
12+
project: "tsconfig.json",
1313
},
1414
rules: {
15-
semi: ['error', 'never'],
16-
'no-extra-semi': ['off'],
15+
semi: ["error", "never"],
16+
"no-extra-semi": ["off"],
1717
},
18-
ignorePatterns: ['src/*.test.js'],
19-
}
18+
ignorePatterns: ["src/*.test.js"],
19+
};

client/examples/commonJS-usage/index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,51 @@
1616
* endpoint from which the consent status can be fetched or to which it can be sent.
1717
*/
1818

19-
const { GovSingleConsent } = require('govuk-single-consent')
19+
const { GovSingleConsent } = require("govuk-single-consent");
2020

21-
const SINGLE_CONSENT_API_BASE_URL = 'dummy-url.gov.uk'
21+
const SINGLE_CONSENT_API_BASE_URL = "dummy-url.gov.uk";
2222

2323
const onConsentsUpdated = (consents, consentsPreferencesSet, error) => {
2424
// Do something with the consents
2525
// e.g
2626

2727
if (consentsPreferencesSet) {
28-
hideCookieBanner()
28+
hideCookieBanner();
2929
}
3030

3131
if (error) {
32-
sendErrorLog(error)
32+
sendErrorLog(error);
3333
}
34-
}
34+
};
3535

3636
const singleConsent = new GovSingleConsent(
3737
onConsentsUpdated,
38-
SINGLE_CONSENT_API_BASE_URL
39-
)
38+
SINGLE_CONSENT_API_BASE_URL,
39+
);
4040

4141
/**
4242
* Some Cookie Banner Event Handlers
4343
*/
4444

4545
const onRejectAllButtonClick = () => {
46-
singleConsent.setConsents(GovSingleConsent.REJECT_ALL)
47-
}
46+
singleConsent.setConsents(GovSingleConsent.REJECT_ALL);
47+
};
4848

4949
const onAcceptAllButtonClick = () => {
50-
singleConsent.setConsents(GovSingleConsent.ACCEPT_ALL)
51-
}
50+
singleConsent.setConsents(GovSingleConsent.ACCEPT_ALL);
51+
};
5252

5353
const onAcceptCustomConsentsButtonClick = (customConsents) => {
54-
singleConsent.setConsents(customConsents)
55-
}
54+
singleConsent.setConsents(customConsents);
55+
};
5656

5757
/**
5858
* Some Logic That Depends On Consents
5959
*/
6060

6161
const sendToAnalytics = (event) => {
6262
if (!GovSingleConsent.hasConsentedToUsage()) {
63-
return
63+
return;
6464
}
6565
// Send event to analytics here
66-
}
66+
};

client/examples/cookie-banner.js

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,110 @@
11
/* global GovSingleConsent */
22

3-
;(function () {
3+
(function () {
44
function CookieBanner($component) {
5-
this.$component = $component
5+
this.$component = $component;
66
}
77

88
CookieBanner.prototype.init = function () {
9-
this.$component.hidden = true
9+
this.$component.hidden = true;
1010

1111
this.$component.message = this.$component.querySelector(
12-
'.js-cookie-banner-message'
13-
)
12+
".js-cookie-banner-message",
13+
);
1414
this.$component.confirmAccept = this.$component.querySelector(
15-
'.js-cookie-banner-confirmation-accept'
16-
)
15+
".js-cookie-banner-confirmation-accept",
16+
);
1717
this.$component.confirmReject = this.$component.querySelector(
18-
'.js-cookie-banner-confirmation-reject'
19-
)
18+
".js-cookie-banner-confirmation-reject",
19+
);
2020

21-
this.$component.setCookieConsent = this.acceptCookies.bind(this)
21+
this.$component.setCookieConsent = this.acceptCookies.bind(this);
2222
this.$component.showAcceptConfirmation =
23-
this.showAcceptConfirmation.bind(this)
23+
this.showAcceptConfirmation.bind(this);
2424
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);
2828
this.$component.showRejectConfirmation =
29-
this.showRejectConfirmation.bind(this)
29+
this.showRejectConfirmation.bind(this);
3030
this.$component
31-
.querySelector('[data-reject-cookies]')
32-
.addEventListener('click', this.$component.rejectCookieConsent)
31+
.querySelector("[data-reject-cookies]")
32+
.addEventListener("click", this.$component.rejectCookieConsent);
3333

3434
var hideBannerBtnNodes = this.$component.querySelectorAll(
35-
'[data-hide-cookie-message]'
36-
)
35+
"[data-hide-cookie-message]",
36+
);
3737
for (var i = 0, length = hideBannerBtnNodes.length; i < length; i++) {
3838
hideBannerBtnNodes[i].addEventListener(
39-
'click',
40-
this.hideBanner.bind(this)
41-
)
39+
"click",
40+
this.hideBanner.bind(this),
41+
);
4242
}
4343

4444
function onConsentsUpdated(consents, consentsPreferencesSet, error) {
4545
if (consentsPreferencesSet) {
46-
this.hideBanner()
46+
this.hideBanner();
4747
} else {
48-
this.showBanner()
48+
this.showBanner();
4949
}
5050
if (error) {
51-
console.error(error)
51+
console.error(error);
5252
}
5353
}
5454

5555
this.singleConsent = new GovSingleConsent(
5656
onConsentsUpdated.bind(this),
57-
window.GovSingleConsentApiBaseURL
58-
)
59-
}
57+
window.GovSingleConsentApiBaseURL,
58+
);
59+
};
6060

6161
CookieBanner.prototype.showBanner = function () {
6262
var acceptedAdditionalCookies =
6363
GovSingleConsent.hasConsentedToUsage() ||
6464
GovSingleConsent.hasConsentedToCampaigns() ||
65-
GovSingleConsent.hasConsentedToSettings()
65+
GovSingleConsent.hasConsentedToSettings();
6666

67-
this.$component.hidden = false
67+
this.$component.hidden = false;
6868
this.$component.confirmAccept.hidden =
69-
!GovSingleConsent.isConsentPreferencesSet() || !acceptedAdditionalCookies
69+
!GovSingleConsent.isConsentPreferencesSet() || !acceptedAdditionalCookies;
7070
this.$component.confirmReject.hidden =
71-
!GovSingleConsent.isConsentPreferencesSet() || acceptedAdditionalCookies
72-
}
71+
!GovSingleConsent.isConsentPreferencesSet() || acceptedAdditionalCookies;
72+
};
7373

7474
CookieBanner.prototype.hideBanner = function () {
75-
this.$component.hidden = true
76-
}
75+
this.$component.hidden = true;
76+
};
7777

7878
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+
};
8282

8383
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+
};
8888

8989
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+
};
9393

9494
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+
};
9999

100-
window.CookieBanner = CookieBanner
100+
window.CookieBanner = CookieBanner;
101101

102-
document.addEventListener('DOMContentLoaded', function () {
102+
document.addEventListener("DOMContentLoaded", function () {
103103
var nodes = document.querySelectorAll(
104-
'[data-module~="govuk-cookie-banner"]'
105-
)
104+
'[data-module~="govuk-cookie-banner"]',
105+
);
106106
for (var i = 0, length = nodes.length; i < length; i++) {
107-
new CookieBanner(nodes[i]).init()
107+
new CookieBanner(nodes[i]).init();
108108
}
109-
})
110-
})()
109+
});
110+
})();

0 commit comments

Comments
 (0)