@getdesigned-vienna/cookie-consent
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -15,2 +15,3 @@ function GdCookieConsent(debug = false) { | ||
if (!this.bindJqEvents()) return; | ||
this.deleteCookies(); | ||
this.updateContent(); | ||
@@ -37,2 +38,3 @@ } | ||
this.warn('Element(s) with selector "' + optIn + '" found, which do not have set the class ".gdcc-hide" hardcoded (but should have)'); | ||
this.warn($optInEls.filter(':not(.gdcc-hide)')); | ||
} | ||
@@ -170,2 +172,3 @@ $optInEls.removeClass('gdcc-hide'); | ||
that.saveUserSettings(that, this); | ||
that.deleteCookies(); | ||
that.updateContent(); | ||
@@ -179,2 +182,26 @@ }); | ||
this.deleteCookies = function () { | ||
var i = 0; | ||
while (i < this.config.length) { | ||
if (this.config[i].checked === 0) { | ||
$el = this.$gdcc.find('#' + this.config[i].id); | ||
this.log('checking for cookies for #' + this.config[i].id); | ||
var deleteCookie = this.getAttribute($el, 'data-gdcc-delete-cookie'); | ||
if (deleteCookie) { | ||
deleteCookie = this._explode(deleteCookie); | ||
this.log('found ' + deleteCookie.length + ' cookies for #' + this.config[i].id); | ||
var j = 0; | ||
while (j < deleteCookie.length) { | ||
cookie(deleteCookie[j], false); | ||
this.log('trying to delete cookie "' + deleteCookie[j] + '" for #' + this.config[i].id); | ||
j++; | ||
} | ||
} else { | ||
this.log('XX nothing found'); | ||
} | ||
} | ||
i++; | ||
} | ||
} | ||
this.saveUserSettings = function (context, button = false) { | ||
@@ -190,8 +217,10 @@ if (button) { | ||
this._explode = function (input) { | ||
return input.toString().trim().replace(/[ ,]{1,}/g, ',').split(','); | ||
} | ||
this._preselectCheckboxes = function (button) { | ||
var $button = $(button); | ||
if ($button.attr('data-gdcc-select')) { | ||
var selector = $button.attr('data-gdcc-select').toString().trim(); | ||
// Normalize spaces and commas to single commas only | ||
selector = selector.replace(/[ ,]{1,}/g, ',').split(','); | ||
var selector = this._explode($button.attr('data-gdcc-select')); | ||
var i = 0; | ||
@@ -243,3 +272,3 @@ while (i < selector.length) { | ||
this.initWrapper = function () { | ||
this.$gdcc = $('#gd-cookie-consent'); | ||
this.$gdcc = $('#gd-cookie-consent, #gdcc-wrapper'); | ||
if (this.$gdcc.length === 0) { | ||
@@ -246,0 +275,0 @@ this.error('GdCookieConsent Wrapper not found: can not find element with id "#gd-cookie-consent". Please add.'); |
{ | ||
"name": "@getdesigned-vienna/cookie-consent", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Cookie Consent completely configured via HTML", | ||
@@ -5,0 +5,0 @@ "main": "getdesigned-cookie-consent.js", |
@@ -24,3 +24,3 @@ Getdesigned Cookie Consent (GDCC) | ||
<div id="gd-cookie-consent"> | ||
<div id="gdcc-wrapper"> | ||
<noscript>...</noscript> | ||
@@ -66,3 +66,3 @@ <form> | ||
<div> | ||
<img class="gdcc-optin-image" data-gdcc-src="https://placekitten.com/g/300/200"/> | ||
<img class="gdcc-optin-image gdcc-hide" data-gdcc-src="https://placekitten.com/g/300/200"/> | ||
<div class="gdcc-optout-image"><h2 style="background-color: forestgreen">Image Replacement #1</h2></div> | ||
@@ -95,6 +95,6 @@ </div> | ||
<div id="gd-cookie-consent" data-gdcc-msg='You must accept cookies in the category "@cookie@" to show this content. Proceed?'> | ||
<div id="gdcc-wrapper" data-gdcc-msg='You must accept cookies in the category "@cookie@" to show this content. Proceed?'> | ||
* The string "@cookie@" will automatically be replaced by the label of the cookies checkbox. | ||
* If the user confirms, the cookie will be enabled and the changed setting is saved. | ||
* A more specific note can be placed on the input or the label itself. If available, it will be taken instead of the general message from the wrapper: | ||
* A more specific message can be placed on the input or the label itself. If available, it will be taken instead of the general message from the wrapper: | ||
@@ -104,3 +104,9 @@ <input type="checkbox" id="image" data-gdcc-msg='Enable cookie category "@cookie@"?' /> | ||
## Keep your cookies clean | ||
* If a cookie is activated even only for a short time, it will stay in memory of your browser | ||
* GDCC is capable of deleting those (first party) cookies, if the category gets disabled again. | ||
* To make this work, make sure you configure the name of the cookies to be delete in an optional attribute "data-gdcc-delete-cookie". The attribute accepts one or more cookie names space or comma separated: | ||
<input type="checkbox" id="extfonts" data-gdcc-delete-cookie="cookieNo1, cookieNo2"/> | ||
Sorry, the diff of this file is not supported yet
27930
300
108