Socket
Socket
Sign inDemoInstall

@dmstr/cookie-consent

Package Overview
Dependencies
0
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.0 to 0.4.0

2

dist/cookie-consent.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.CookieConsent=e():t.CookieConsent=e()}(window,(function(){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,o),s.l=!0,s.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)o.d(n,s,function(e){return t[e]}.bind(null,s));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0)}([function(t,e,o){"use strict";o.r(e);var n=function(t){this.defaultsOptions={name:"cookie_consent_status",value:[],path:"/",domain:"",expiryDays:365},this.options=this.mergeObjects(this.defaultsOptions,t),this.inputs=[].slice.call(document.querySelectorAll("[data-cc-consent]")),this.popup=document.querySelector(".cookie-consent-popup"),this.controls=document.querySelector(".cookie-consent-controls"),this.details=document.querySelector(".cookie-consent-details"),this.saveButtons=[].slice.call(document.querySelectorAll(".cookie-consent-save")),this.acceptAllButtons=[].slice.call(document.querySelectorAll(".cookie-consent-accept-all")),this.denyAllButtons=[].slice.call(document.querySelectorAll(".cookie-consent-deny-all")),this.openControlsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-controls-open")),this.closeControlsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-controls-close")),this.openDetailsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-details-open")),this.closeDetailsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-details-close")),this.openButtons=[].slice.call(document.querySelectorAll(".cookie-consent-open")),this.closeButtons=[].slice.call(document.querySelectorAll(".cookie-consent-close")),this.addEventListeners(),void 0===this.get()&&this.open(),this.refreshUI()};n.prototype.open=function(){this.popup&&this.popup.classList.add("open")},n.prototype.close=function(){this.popup&&this.popup.classList.remove("open")},n.prototype.openControls=function(){this.controls&&this.controls.classList.add("open")},n.prototype.closeControls=function(){this.controls&&this.controls.classList.remove("open")},n.prototype.openDetails=function(){this.details&&this.details.classList.add("open")},n.prototype.closeDetails=function(){this.details&&this.details.classList.remove("open")},n.prototype.addEventListeners=function(){var t=this;this.openDetailsButtons.length>0&&this.openDetailsButtons.forEach((function(e){e.addEventListener("click",(function(){t.open(),t.openDetails()}))})),this.closeDetailsButtons.length>0&&this.closeDetailsButtons.forEach((function(e){e.addEventListener("click",(function(){t.closeDetails()}))})),this.openControlsButtons.length>0&&this.openControlsButtons.forEach((function(e){e.addEventListener("click",(function(){t.open(),t.openControls()}))})),this.closeControlsButtons.length>0&&this.closeControlsButtons.forEach((function(e){e.addEventListener("click",(function(){t.closeControls()}))})),this.saveButtons.length>0&&this.saveButtons.forEach((function(e){e.addEventListener("click",(function(){t.save()}))})),this.acceptAllButtons.length>0&&this.acceptAllButtons.forEach((function(e){e.addEventListener("click",(function(){t.inputs.length>0&&t.inputs.forEach((function(t){t.checked=!0})),t.save()}))})),this.denyAllButtons.length>0&&this.denyAllButtons.forEach((function(e){e.addEventListener("click",(function(){t.inputs.length>0&&t.inputs.forEach((function(t){t.checked=!1})),t.save()}))})),this.openButtons.length>0&&this.openButtons.forEach((function(e){e.addEventListener("click",(function(){t.open()}))})),this.closeButtons.length>0&&this.closeButtons.forEach((function(e){e.addEventListener("click",(function(){t.close()}))}))},n.prototype.save=function(){var t=this;this.set(this.options),this.inputs.length>0&&this.inputs.forEach((function(e){var o=e.getAttribute("data-cc-consent");e.checked?t.add(o):t.remove(o)})),this.refreshUI(),this.afterSave(this)},n.prototype.refreshUI=function(){var t=this;void 0!==this.get()&&this.inputs.forEach((function(e){var o=e.getAttribute("data-cc-consent");e.checked=t.has(o)}))},n.prototype.set=function(t){var e=new Date;e.setDate(e.getDate()+(t.expiryDays||365));var o=[t.name+"="+JSON.stringify(t.value),"expires="+e.toUTCString(),"path="+(t.path||"/")];t.domain&&o.push("domain="+t.domain),document.cookie=o.join(";")},n.prototype.get=function(){var t=("; "+document.cookie).split("; "+this.options.name+"="),e=2!==t.length?void 0:t.pop().split(";").shift();return void 0!==e?JSON.parse(e):e},n.prototype.has=function(t){var e=this.get();return void 0!==e&&e.indexOf(t)>-1},n.prototype.add=function(t){var e=this.get();if(void 0!==e&&!e.indexOf(t)>-1){e.push(t);var o=this.mergeObjects(this.defaultsOptions,{value:e});return this.set(o),!0}return!1},n.prototype.remove=function(t){var e=this.get();if(void 0===e)return!1;var o=e.indexOf(t);if(o>-1){e.splice(o,1);var n=this.mergeObjects(this.defaultsOptions,{value:e});return this.set(n),!0}return!1},n.prototype.clean=function(t){for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&!this.has(e)){var o=t[e].cookies;for(var n in o)if(Object.prototype.hasOwnProperty.call(o,n)){var s={name:o[n].name,expiryDays:-1};void 0!==o[n].domain&&(s.domain=o[n].domain),void 0!==o[n].path&&(s.path=o[n].path),this.set(s)}}},n.prototype.mergeObjects=function(){for(var t={},e=0;e<arguments.length;e++)for(var o in arguments[e])Object.prototype.hasOwnProperty.call(arguments[e],o)&&(t[o]=arguments[e][o]);return t},n.prototype.afterSave=function(){},e.default=n}]).default}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.CookieConsent=e():t.CookieConsent=e()}(window,(function(){return function(t){var e={};function o(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,o),s.l=!0,s.exports}return o.m=t,o.c=e,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)o.d(n,s,function(e){return t[e]}.bind(null,s));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0)}([function(t,e,o){"use strict";o.r(e);var n=function(t){this.defaultsOptions={name:"cookie_consent_status",value:[],path:"/",domain:"",expiryDays:365},this.options=this.mergeObjects(this.defaultsOptions,t),this.inputs=[].slice.call(document.querySelectorAll("[data-cc-consent]")),this.popup=document.querySelector(".cookie-consent-popup"),this.controls=document.querySelector(".cookie-consent-controls"),this.details=document.querySelector(".cookie-consent-details"),this.saveButtons=[].slice.call(document.querySelectorAll(".cookie-consent-save")),this.acceptAllButtons=[].slice.call(document.querySelectorAll(".cookie-consent-accept-all")),this.denyAllButtons=[].slice.call(document.querySelectorAll(".cookie-consent-deny-all")),this.openControlsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-controls-open")),this.closeControlsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-controls-close")),this.toggleControlsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-controls-toggle")),this.openDetailsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-details-open")),this.closeDetailsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-details-close")),this.toggleDetailsButtons=[].slice.call(document.querySelectorAll(".cookie-consent-details-toggle")),this.openButtons=[].slice.call(document.querySelectorAll(".cookie-consent-open")),this.closeButtons=[].slice.call(document.querySelectorAll(".cookie-consent-close")),this.toggleButtons=[].slice.call(document.querySelectorAll(".cookie-consent-toggle")),this.addEventListeners(),void 0===this.get()&&this.open(),this.refreshUI()};n.prototype.open=function(){this.popup&&this.popup.classList.add("open")},n.prototype.close=function(){this.popup&&this.popup.classList.remove("open")},n.prototype.openControls=function(){this.controls&&this.controls.classList.add("open")},n.prototype.closeControls=function(){this.controls&&this.controls.classList.remove("open")},n.prototype.openDetails=function(){this.details&&this.details.classList.add("open")},n.prototype.closeDetails=function(){this.details&&this.details.classList.remove("open")},n.prototype.addEventListeners=function(){var t=this;this.toggleButtons.length>0&&this.toggleButtons.forEach((function(e){e.addEventListener("click",(function(){t.popup.classList.contains("open")?t.close():t.open()}))})),this.openDetailsButtons.length>0&&this.openDetailsButtons.forEach((function(e){e.addEventListener("click",(function(){t.open(),t.openDetails()}))})),this.closeDetailsButtons.length>0&&this.closeDetailsButtons.forEach((function(e){e.addEventListener("click",(function(){t.closeDetails()}))})),this.toggleDetailsButtons.length>0&&this.toggleDetailsButtons.forEach((function(e){e.addEventListener("click",(function(){t.details.classList.contains("open")?t.closeDetails():(t.open(),t.openDetails())}))})),this.openControlsButtons.length>0&&this.openControlsButtons.forEach((function(e){e.addEventListener("click",(function(){t.open(),t.openControls()}))})),this.closeControlsButtons.length>0&&this.closeControlsButtons.forEach((function(e){e.addEventListener("click",(function(){t.closeControls()}))})),this.toggleControlsButtons.length>0&&this.toggleControlsButtons.forEach((function(e){e.addEventListener("click",(function(){t.controls.classList.contains("open")?t.closeControls():(t.open(),t.openControls())}))})),this.saveButtons.length>0&&this.saveButtons.forEach((function(e){e.addEventListener("click",(function(){t.save()}))})),this.acceptAllButtons.length>0&&this.acceptAllButtons.forEach((function(e){e.addEventListener("click",(function(){t.inputs.length>0&&t.inputs.forEach((function(t){t.checked=!0})),t.save()}))})),this.denyAllButtons.length>0&&this.denyAllButtons.forEach((function(e){e.addEventListener("click",(function(){t.inputs.length>0&&t.inputs.forEach((function(t){t.checked=!1})),t.save()}))})),this.openButtons.length>0&&this.openButtons.forEach((function(e){e.addEventListener("click",(function(){t.open()}))})),this.closeButtons.length>0&&this.closeButtons.forEach((function(e){e.addEventListener("click",(function(){t.close()}))}))},n.prototype.save=function(){var t=this;this.set(this.options),this.inputs.length>0&&this.inputs.forEach((function(e){var o=e.getAttribute("data-cc-consent");e.checked?t.add(o):t.remove(o)})),this.refreshUI(),this.afterSave(this)},n.prototype.refreshUI=function(){var t=this;void 0!==this.get()&&this.inputs.forEach((function(e){var o=e.getAttribute("data-cc-consent");e.checked=t.has(o)}))},n.prototype.set=function(t){var e=new Date;e.setDate(e.getDate()+(t.expiryDays||365));var o=[t.name+"="+JSON.stringify(t.value),"expires="+e.toUTCString(),"path="+(t.path||"/")];t.domain&&o.push("domain="+t.domain),document.cookie=o.join(";")},n.prototype.get=function(){var t=("; "+document.cookie).split("; "+this.options.name+"="),e=2!==t.length?void 0:t.pop().split(";").shift();return void 0!==e?JSON.parse(e):e},n.prototype.has=function(t){var e=this.get();return void 0!==e&&e.indexOf(t)>-1},n.prototype.add=function(t){var e=this.get();if(void 0!==e&&!e.indexOf(t)>-1){e.push(t);var o=this.mergeObjects(this.defaultsOptions,{value:e});return this.set(o),!0}return!1},n.prototype.remove=function(t){var e=this.get();if(void 0===e)return!1;var o=e.indexOf(t);if(o>-1){e.splice(o,1);var n=this.mergeObjects(this.defaultsOptions,{value:e});return this.set(n),!0}return!1},n.prototype.clean=function(t){for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&!this.has(e)){var o=t[e].cookies;for(var n in o)if(Object.prototype.hasOwnProperty.call(o,n)){var s={name:o[n].name,expiryDays:-1};void 0!==o[n].domain&&(s.domain=o[n].domain),void 0!==o[n].path&&(s.path=o[n].path),this.set(s)}}},n.prototype.mergeObjects=function(){for(var t={},e=0;e<arguments.length;e++)for(var o in arguments[e])Object.prototype.hasOwnProperty.call(arguments[e],o)&&(t[o]=arguments[e][o]);return t},n.prototype.afterSave=function(){},e.default=n}]).default}));
{
"name": "@dmstr/cookie-consent",
"version": "0.3.0",
"version": "0.4.0",
"description": "Library to address GDPR (The General Data Protection Regulation)",

@@ -5,0 +5,0 @@ "main": "dist/cookie-consent.js",

@@ -37,6 +37,9 @@ [![Build Status](https://travis-ci.org/dmstr/cookie-consent.svg?branch=master)](https://travis-ci.org/dmstr/cookie-consent)

<button class="cookie-consent-close">close</button>
<button class="cookie-consent-toggle">toggle</button>
<button class="cookie-consent-controls-open">Open controls</button>
<button class="cookie-consent-controls-close">Close controls</button>
<button class="cookie-consent-controls-toggle">Toggle controls</button>
<button class="cookie-consent-details-open">Open Details</button>
<button class="cookie-consent-details-close">Close Details</button>
<button class="cookie-consent-details-toggle">Toggle details</button>

@@ -195,6 +198,9 @@ <!-- the popup that will appear if no consent cookie where saved -->

* `cookie-consent-close`: closes the popup.
* `cookie-consent-toggle`: toggles the popup.
* `cookie-consent-controls-open`: opens the controls
* `cookie-consent-controls-close`: closes the controls
* `cookie-consent-controls-toggle`: toggles the controls
* `cookie-consent-details-open`: opens the details
* `cookie-consent-details-close`: closes the details
* `cookie-consent-details-toggle`: toggles the details
* `data-cc-consent`: the consent name/value that will be stored in the consent cookie.

@@ -201,0 +207,0 @@ * `data-cc-namespace`: used to group checkboxes and save buttons. In that way you can add different groups in different zones of your website without conflicting with other checkboxes or save buttons.

@@ -19,6 +19,9 @@ const CookieConsent = function (options) {

this.closeControlsButtons = [].slice.call(document.querySelectorAll('.cookie-consent-controls-close'))
this.toggleControlsButtons = [].slice.call(document.querySelectorAll('.cookie-consent-controls-toggle'))
this.openDetailsButtons = [].slice.call(document.querySelectorAll('.cookie-consent-details-open'))
this.closeDetailsButtons = [].slice.call(document.querySelectorAll('.cookie-consent-details-close'))
this.toggleDetailsButtons = [].slice.call(document.querySelectorAll('.cookie-consent-details-toggle'))
this.openButtons = [].slice.call(document.querySelectorAll('.cookie-consent-open'))
this.closeButtons = [].slice.call(document.querySelectorAll('.cookie-consent-close'))
this.toggleButtons = [].slice.call(document.querySelectorAll('.cookie-consent-toggle'))

@@ -69,2 +72,13 @@ this.addEventListeners()

CookieConsent.prototype.addEventListeners = function () {
if (this.toggleButtons.length > 0) {
this.toggleButtons.forEach((button) => {
button.addEventListener('click', () => {
if (this.popup.classList.contains('open')) {
this.close()
} else {
this.open()
}
})
})
}
if (this.openDetailsButtons.length > 0) {

@@ -85,2 +99,14 @@ this.openDetailsButtons.forEach((openDetailsButton) => {

}
if (this.toggleDetailsButtons.length > 0) {
this.toggleDetailsButtons.forEach((toggleDetailsButton) => {
toggleDetailsButton.addEventListener('click', () => {
if (this.details.classList.contains('open')) {
this.closeDetails()
} else {
this.open()
this.openDetails()
}
})
})
}
if (this.openControlsButtons.length > 0) {

@@ -101,2 +127,14 @@ this.openControlsButtons.forEach((openControlsButton) => {

}
if (this.toggleControlsButtons.length > 0) {
this.toggleControlsButtons.forEach((toggleControlsButton) => {
toggleControlsButton.addEventListener('click', () => {
if (this.controls.classList.contains('open')) {
this.closeControls()
} else {
this.open()
this.openControls()
}
})
})
}
if (this.saveButtons.length > 0) {

@@ -202,3 +240,2 @@ this.saveButtons.forEach((saveButton) => {

const value = this.get()
// return (typeof value !== 'undefined' && value.includes(consent))
return (typeof value !== 'undefined' && value.indexOf(consent) > -1)

@@ -209,3 +246,2 @@ }

const value = this.get()
// if (typeof value !== 'undefined' && !value.includes(consent)) {
if (typeof value !== 'undefined' && !value.indexOf(consent) > -1) {

@@ -212,0 +248,0 @@ value.push(consent)

@@ -8,2 +8,3 @@ /* global Feature Scenario */

Scenario('should work correctly', async function (I) {
// initial state
I.amOnPage('cookie-consent.html')

@@ -20,2 +21,4 @@ I.dontSeeCookie('cookie_consent_status')

I.dontSeeCheckboxIsChecked('[data-cc-consent="extern-media"]')
// allow single consents
I.checkOption('[data-cc-consent="statistics"]')

@@ -30,2 +33,4 @@ I.checkOption('[data-cc-consent="extern-media"]')

assert.deepStrictEqual(cookie.value, '["statistics","extern-media"]')
// dissallow some consents
I.click('.cookie-consent-open')

@@ -54,2 +59,4 @@ I.waitForVisible('.cookie-consent-popup', 5);

I.dontSeeCheckboxIsChecked('[data-cc-consent="extern-media"]')
// open and close buttons
I.click('.cookie-consent-close')

@@ -76,2 +83,34 @@ I.waitForInvisible('.cookie-consent-popup', 5);

I.waitForInvisible('.cookie-consent-details', 5);
// toggle buttons
I.click('.cookie-consent-close')
I.click('.cookie-consent-controls-close')
I.click('.cookie-consent-details-close')
I.waitForInvisible('.cookie-consent-popup', 5);
I.waitForInvisible('.cookie-consent-controls', 5);
I.waitForInvisible('.cookie-consent-details', 5);
I.click('.cookie-consent-toggle')
I.waitForVisible('.cookie-consent-popup', 5);
I.click('.cookie-consent-toggle')
I.waitForInvisible('.cookie-consent-popup', 5);
// control toggle buttons
I.click('.cookie-consent-close')
I.click('.cookie-consent-controls-toggle')
I.waitForVisible('.cookie-consent-popup', 5);
I.waitForVisible('.cookie-consent-controls', 5);
I.click('.cookie-consent-controls-toggle')
I.waitForVisible('.cookie-consent-popup', 5);
I.waitForInvisible('.cookie-consent-controls', 5);
// details toggle buttons
I.click('.cookie-consent-close')
I.click('.cookie-consent-details-toggle')
I.waitForVisible('.cookie-consent-popup', 5);
I.waitForVisible('.cookie-consent-details', 5);
I.click('.cookie-consent-details-toggle')
I.waitForVisible('.cookie-consent-popup', 5);
I.waitForInvisible('.cookie-consent-details', 5);
// accept all
I.click('.cookie-consent-accept-all')

@@ -89,2 +128,4 @@ I.seeCookie('cookie_consent_status')

I.waitForVisible('.cookie-consent-save', 5);
// deny all
I.click('.cookie-consent-deny-all')

@@ -91,0 +132,0 @@ I.seeCookie('cookie_consent_status')

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc