Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 18, 2023
1 parent b560405 commit 7782825
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 155 deletions.
14 changes: 7 additions & 7 deletions client/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ module.exports = {
es2021: false,
node: true,
},
extends: 'eslint:recommended',
extends: "eslint:recommended",
overrides: [],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: 'tsconfig.json',
sourceType: "module",
project: "tsconfig.json",
},
rules: {
semi: ['error', 'never'],
'no-extra-semi': ['off'],
semi: ["error", "never"],
"no-extra-semi": ["off"],
},
ignorePatterns: ['src/*.test.js'],
}
ignorePatterns: ["src/*.test.js"],
};
30 changes: 15 additions & 15 deletions client/examples/commonJS-usage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,51 @@
* endpoint from which the consent status can be fetched or to which it can be sent.
*/

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

const SINGLE_CONSENT_API_URL = 'dummy-url.gov.uk'
const SINGLE_CONSENT_API_URL = "dummy-url.gov.uk";

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

if (consentsPreferencesSet) {
hideCookieBanner()
hideCookieBanner();
}

if (error) {
sendErrorLog(error)
sendErrorLog(error);
}
}
};

const singleConsent = new GovSingleConsent(
onConsentsUpdated,
SINGLE_CONSENT_API_URL
)
SINGLE_CONSENT_API_URL,
);

/**
* Some Cookie Banner Event Handlers
*/

const onRejectAllButtonClick = () => {
singleConsent.setConsents(GovSingleConsent.REJECT_ALL)
}
singleConsent.setConsents(GovSingleConsent.REJECT_ALL);
};

const onAcceptAllButtonClick = () => {
singleConsent.setConsents(GovSingleConsent.ACCEPT_ALL)
}
singleConsent.setConsents(GovSingleConsent.ACCEPT_ALL);
};

const onAcceptCustomConsentsButtonClick = (customConsents) => {
singleConsent.setConsents(customConsents)
}
singleConsent.setConsents(customConsents);
};

/**
* Some Logic That Depends On Consents
*/

const sendToAnalytics = (event) => {
if (!GovSingleConsent.hasConsentedToUsage()) {
return
return;
}
// Send event to analytics here
}
};
112 changes: 56 additions & 56 deletions client/examples/cookie-banner.js
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();
}
})
})()
});
})();
Loading

0 comments on commit 7782825

Please sign in to comment.