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.2.0 to 0.3.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.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.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.addEventListeners=function(){var t=this;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.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}));
{
"name": "@dmstr/cookie-consent",
"version": "0.2.0",
"version": "0.3.0",
"description": "Library to address GDPR (The General Data Protection Regulation)",

@@ -35,3 +35,3 @@ "main": "dist/cookie-consent.js",

"live-server": "^1.2.1",
"webpack": "^4.35.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.5"

@@ -38,0 +38,0 @@ },

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

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

@@ -56,2 +58,19 @@ <!-- the popup that will appear if no consent cookie where saved -->

</div>
<div class="cookie-consent-details open">
<h2>Statistics</h2>
<table style="width:100%">
<tr>
<td>Name</td>
<td>Statistics</td>
</tr>
<tr>
<td>Goal</td>
<td>Create statistics data</td>
</tr>
<tr>
<td>Cookie Names</td>
<td>_ga, _gat, _gid, _gali</td>
</tr>
</table>
</div>
</div>

@@ -101,2 +120,14 @@

.cookie-consent-details {
max-height: 0;
overflow: hidden;
-webkit-transition: max-height 0.5s ease-out;
-moz-transition: max-height 0.5s ease-out;
transition: max-height 0.5s ease-out;
}
.cookie-consent-details.open {
max-height: 600px;
}
@keyframes show {

@@ -111,2 +142,4 @@ from {opacity: 0;}

}
```

@@ -165,3 +198,6 @@

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

@@ -168,0 +204,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.

@@ -13,2 +13,3 @@ const CookieConsent = function (options) {

this.controls = document.querySelector('.cookie-consent-controls')
this.details = document.querySelector('.cookie-consent-details')
this.saveButtons = [].slice.call(document.querySelectorAll('.cookie-consent-save'))

@@ -19,2 +20,4 @@ this.acceptAllButtons = [].slice.call(document.querySelectorAll('.cookie-consent-accept-all'))

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'))

@@ -54,3 +57,30 @@ this.closeButtons = [].slice.call(document.querySelectorAll('.cookie-consent-close'))

CookieConsent.prototype.openDetails = function () {
if (this.details) {
this.details.classList.add('open')
}
}
CookieConsent.prototype.closeDetails = function () {
if (this.details) {
this.details.classList.remove('open')
}
}
CookieConsent.prototype.addEventListeners = function () {
if (this.openDetailsButtons.length > 0) {
this.openDetailsButtons.forEach((openDetailsButton) => {
openDetailsButton.addEventListener('click', () => {
this.open()
this.openDetails()
})
})
}
if (this.closeDetailsButtons.length > 0) {
this.closeDetailsButtons.forEach((closeDetailsButton) => {
closeDetailsButton.addEventListener('click', () => {
this.closeDetails()
})
})
}
if (this.openControlsButtons.length > 0) {

@@ -57,0 +87,0 @@ this.openControlsButtons.forEach((openControlsButton) => {

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

I.waitForInvisible('.cookie-consent-save', 5);
I.click('.cookie-consent-details-open')
I.waitForVisible('.cookie-consent-popup', 5);
I.waitForVisible('.cookie-consent-details', 5);
I.click('.cookie-consent-details-close')
I.waitForVisible('.cookie-consent-popup', 5);
I.waitForInvisible('.cookie-consent-details', 5);
I.click('.cookie-consent-accept-all')

@@ -68,0 +74,0 @@ I.seeCookie('cookie_consent_status')

Sorry, the diff of this file is not supported yet

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