https://github.com/jitesoft/node-cookie-sanction
Mirror for the cookie-sanction node module.
https://github.com/jitesoft/node-cookie-sanction
cookie-consent cookies gdpr javascript webpack
Last synced: 29 days ago
JSON representation
Mirror for the cookie-sanction node module.
- Host: GitHub
- URL: https://github.com/jitesoft/node-cookie-sanction
- Owner: jitesoft
- License: mit
- Created: 2018-03-07T18:24:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T02:08:27.000Z (over 3 years ago)
- Last Synced: 2025-01-04T10:08:46.744Z (over 1 year ago)
- Topics: cookie-consent, cookies, gdpr, javascript, webpack
- Language: JavaScript
- Size: 974 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cookie Sanction / Cookie Consent
A JavaScript module for front-end cookie consent functionality which allows for loading scripts after consent is
accepted.
The dist build is compiled to cover latest browsers while compiling from source with your own tool might be more preferable.
## Vanilla js
### Installation and usage
Install the module from any of the standard channels:
```text
yarn add cookie-sanction
npm install cookie-sanction --save
```
Include it in your own JavaScript as a module
```javascript
import { CookieSanction } from 'cookie-sanction';
// alt: { CookieConsent } -"-
// alt: default
const consent = new CookieSanction({
/* options */
});
document.addEventListener('DOMContentLoaded', () => {
consent.active().then((accepted) => {
// accepted is true if user accepted, else false.
}).catch(() => {
});
});
```
### Optional arguments
When creating the cookie consent object, you can change a few default values:
```javascript
const defaults = {
element: 'div.cookie-consent', // The element that will toggle hidden or shown.
cookie: 'accept-cookies', // Name of the cookie to use.
cookieValue: 'accepted', // Cookie value.
hiddenClass: 'hidden', // Class to toggle to hide/show the element.
rejectButton: 'div.cookie-consent button[name="reject"]', // Selector for the button which rejects cookies.
acceptButton: 'div.cookie-consent button[name="accept"]' // Selector for the button which accept cookies.
};
```
Just pass in an object with the properties you wish to change from the default, it will merge the options with the default values.
## Examples
Check the [`example/`](https://gitlab.com/jitesoft/open-source/javascript/cookie-consent/tree/master/example) directory.