Skip to content

Commit

Permalink
Add option for data-tnacookiespath attribute on <html>
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Dec 9, 2024
1 parent af6058d commit e858d30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- The `data-tnacookiesdomain` attribute of the `<html>` element can be used to define the domain for cookies
- Optional `data-tnacookiesdomain` and `data-tnacookiespath` attributes on the `<html>` element can be used to define the domain and path for cookies

### Changed

- Shifted and split hero components no longer assume a contrasted background by default
- `marketing` has been added to the default list of cookie policies

### Deprecated
### Removed
Expand Down
12 changes: 9 additions & 3 deletions src/nationalarchives/lib/cookies.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class Cookies {

/**
* Create a cookie handler.
* @param {String} [options.extraPolicies=[]] - The extra cookie policies to manage in addition to essential, settings and usage.
* @param {String} [options.extraPolicies=[]] - The extra cookie policies to manage in addition to essential, settings, usage and marketing.
* @param {String} [options.domain=""] - The domain to register the cookie with.
* @param {String} [options.path=""] - The domain to register the cookie with.
* @param {String} [options.secure=true] - Only set cookie in HTTPS environments.
Expand All @@ -84,7 +84,7 @@ export default class Cookies {
const {
extraPolicies = [],
domain = null,
path = "/",
path = null,
secure = true,
policiesKey = "cookies_policy",
newInstance = false,
Expand All @@ -102,7 +102,12 @@ export default class Cookies {
} else {
this.domain = domain;
}
this.path = path;
if (path === null) {
this.path =
document.documentElement.getAttribute("data-tnacookiespath") || "/";
} else {
this.path = path;
}
this.secure = secure;
this.policiesKey = policiesKey;
this.defaultAge = defaultAge;
Expand All @@ -119,6 +124,7 @@ export default class Cookies {
),
usage: false,
settings: false,
marketing: false,
...this.policies,
essential: true,
});
Expand Down

0 comments on commit e858d30

Please sign in to comment.