cookieyesno
Advanced tools
Comparing version 1.1.0 to 1.1.1
'use strict'; | ||
/*! | ||
CookieYesNo | philippG777 | https://github.com/philippG777/cookieyesno | MIT License | ||
/** | ||
* @license | ||
* CookieYesNo | https://github.com/philippG777/cookieyesno | BSD 4-Clause License (Modified) | ||
* Copyright (c) 2021 Philipp Gretzl | ||
*/ | ||
// TODO: | ||
// Load blocked scripts | ||
// reload on reject (by default true) none | ||
class CookieYesNo { | ||
constructor(config) { | ||
this.version = '1.1.0'; | ||
this.version = '1.1.1'; | ||
this.cookie = { // cookie handler | ||
@@ -33,2 +31,7 @@ set: function(data) { | ||
}; | ||
// IE polyfill | ||
if (window.NodeList && !NodeList.prototype.forEach) { | ||
NodeList.prototype.forEach = Array.prototype.forEach; | ||
} | ||
@@ -122,7 +125,7 @@ this._config = config; | ||
const textAbove = (this._config.text != undefined && this._config.text.above != undefined)? | ||
this._config.text.above : 'This website uses cookies.\ | ||
You can choose below which cookies may be stored on your device. You can allow all cookies using\ | ||
the "Accept all cookies" button or accept a selection of cookies by using the\ | ||
"Accept selected cookies" button and the checkboxes to select cookie categories.\ | ||
You can review and revoke consent at any time using the "Review cookie settings" link in the footer.'; | ||
this._config.text.above : 'This website uses cookies.' + | ||
'You can choose below which cookies may be stored on your device. You can allow all cookies using' + | ||
'the "Accept all cookies" button or accept a selection of cookies by using the' + | ||
'"Accept selected cookies" button and the checkboxes to select cookie categories.' + | ||
'You can review and revoke consent at any time using the "Review cookie settings" link in the footer.'; | ||
@@ -129,0 +132,0 @@ const textBelow = (this._config.text != undefined && this._config.text.below != undefined)? |
var CookieYesNo = (function () { | ||
'use strict'; | ||
/*! | ||
CookieYesNo | philippG777 | https://github.com/philippG777/cookieyesno | MIT License | ||
/** | ||
* @license | ||
* CookieYesNo | https://github.com/philippG777/cookieyesno | BSD 4-Clause License (Modified) | ||
* Copyright (c) 2021 Philipp Gretzl | ||
*/ | ||
// TODO: | ||
// Load blocked scripts | ||
// reload on reject (by default true) none | ||
var CookieYesNo = function CookieYesNo(config) { | ||
var this$1 = this; | ||
this.version = '1.1.0'; | ||
this.version = '1.1.1'; | ||
this.cookie = { // cookie handler | ||
@@ -35,2 +33,7 @@ set: function(data) { | ||
}; | ||
// IE polyfill | ||
if (window.NodeList && !NodeList.prototype.forEach) { | ||
NodeList.prototype.forEach = Array.prototype.forEach; | ||
} | ||
@@ -124,7 +127,7 @@ this._config = config; | ||
var textAbove = (this._config.text != undefined && this._config.text.above != undefined)? | ||
this._config.text.above : 'This website uses cookies.\ | ||
You can choose below which cookies may be stored on your device. You can allow all cookies using\ | ||
the "Accept all cookies" button or accept a selection of cookies by using the\ | ||
"Accept selected cookies" button and the checkboxes to select cookie categories.\ | ||
You can review and revoke consent at any time using the "Review cookie settings" link in the footer.'; | ||
this._config.text.above : 'This website uses cookies.' + | ||
'You can choose below which cookies may be stored on your device. You can allow all cookies using' + | ||
'the "Accept all cookies" button or accept a selection of cookies by using the' + | ||
'"Accept selected cookies" button and the checkboxes to select cookie categories.' + | ||
'You can review and revoke consent at any time using the "Review cookie settings" link in the footer.'; | ||
@@ -131,0 +134,0 @@ var textBelow = (this._config.text != undefined && this._config.text.below != undefined)? |
@@ -1,1 +0,6 @@ | ||
var CookieYesNo=function(){"use strict";function t(t){var n=this;function e(t,e){void 0===n._config[t]&&(n._config[t]=e)}this.version="1.1.0",this.cookie={set:function(t){var e=new Date;e.setTime(e.getTime()+7776e6),document.cookie="_cyn="+t+";expires="+e.toUTCString()+";path=/;SameSite=Lax"},get:function(){for(var t=document.cookie.split(";"),e=0;e<t.length;e++){var n=t[e].trim().split("=");if("_cyn"==n[0])return n[1]}return null},clear:function(){document.cookie="_cyn=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;SameSite=Lax"}},this._config=t,e("title","Cookie Settings"),e("acceptAllButtonText","Accept all cookies"),e("acceptSelectionButtonText","Accept selected cookies");var i=["onAccept","onReject","onChange"];this._loopOverCategories(function(e){i.forEach(function(t){void 0===e[t]&&(e[t]=[])})}),this.banner=this._createBanner(),this._applyStyle(),this._addListeners();var o=this._load();null==o?this.show():o.version!=this.version||null!=this._config.version&&this._config.version!=o.configversion?(this.cookie.clear(),this.show()):this._runListeners()}return t.prototype._load=function(){var t=this.cookie.get();return null==t?null:JSON.parse(t)},t.prototype._save=function(t){var e={version:this.version,settings:t};null!=this._config.version&&(e.configversion=this._config.version),this.cookie.set(JSON.stringify(e))},t.prototype.getSettings=function(){var t=this._load();return null==t?{}:t.settings},t.prototype.onChange=function(t,e){this._config.categories[t].onChange.push(e)},t.prototype.onAccept=function(t,e){!0===this.getSettings()[t]&&e(),this._config.categories[t].onAccept.push(e)},t.prototype.onReject=function(t,e){!1===this.getSettings()[t]&&e(),this._config.categories[t].onReject.push(e)},t.prototype.reviewSettings=function(){this._bannerApplySettings(this.getSettings()),this.show()},t.prototype._createBanner=function(){var t=null!=this._config.text&&null!=this._config.text.above?this._config.text.above:'This website uses cookies. You can choose below which cookies may be stored on your device. You can allow all cookies using the "Accept all cookies" button or accept a selection of cookies by using the "Accept selected cookies" button and the checkboxes to select cookie categories. You can review and revoke consent at any time using the "Review cookie settings" link in the footer.',e=null!=this._config.text&&null!=this._config.text.below?this._config.text.below:"",n=document.createElement("div");n.className="cyn-banner";var i='<h3 style="font-size:28px;font-weight:bold;margin-top:16px;margin-bottom:20px">'+this._config.title+"</h3>";return i+="<p>"+this._insertLinks(t)+"</p>",i+='<button class="cyn-btn-accept-all">'+this._config.acceptAllButtonText+"</button>",i+='<button class="cyn-btn-save">'+this._config.acceptSelectionButtonText+"</button>",i+='<table class="cyn-categories"><tbody>',this._loopOverCategories(function(t,e){i+='<tr><td style="font-weight:bold">'+t.name+"</td><td>"+t.description+"</td><td>",i+='<input type="checkbox" value="'+e+'"'+(t.accepted?" checked":"")+(!0===t.changeable||void 0===t.changeable?"":" disabled")+"/>",i+="</td></tr>"}),i+="</tbody></table>",i+="<p>"+this._insertLinks(e)+"</p>",i+='<div class="cyn-other-links" style="padding-top:6px;padding-bottom:8px;font-size:12px">',null!=this._config.imprint&&(i+=this._createLink(this._config.imprint)+" "),null!=this._config.privacyPolicy&&(i+=this._createLink(this._config.privacyPolicy)+" "),null!=this._config.cookiePolicy&&(i+=this._createLink(this._config.cookiePolicy)),i+="</div>",n.innerHTML=i,n.style.display="none",document.body.appendChild(n),n},t.prototype._bannerApplySettings=function(t){for(var e=this.banner.getElementsByTagName("input"),n=0;n<e.length;n++)"checkbox"==e[n].type&&(e[n].checked=null!=t[e[n].value]&&1==t[e[n].value])},t.prototype._applyStyle=function(){var t=this.banner.style;t.zIndex=5e3,t.backgroundColor="#fff",t.position="fixed",t.padding="16px",t.boxShadow="0 0 24px #aaa",t.borderRadius="8px",t.fontSize="14px",t.fontFamily='"Trebuchet MS", Helvetica, sans-serif',t.color="#444",t.overflowY="auto",window.innerWidth<=768?(t.top=t.right=t.left=t.bottom="16px",t.maxWidth="80%"):(t.right=t.bottom="32px",t.maxHeight="80vh",t.maxWidth="40%"),(t=this.banner.getElementsByTagName("table")[0].style).margin="16px";for(var e=this.banner.getElementsByTagName("td"),n=0;n<e.length;n++)e[n].style.padding="8px";for(var i=this.banner.getElementsByTagName("button"),o=0;o<i.length;o++)(t=i[o].style).boxSizing="border-box",t.cursor="pointer",t.margin="12px",t.marginLeft="10%",t.borderRadius="4px",t.border="0px",t.backgroundColor="#48c774",t.color="white",t.fontSize="18px",t.padding="8px",t.paddingLeft=t.paddingRight="12px",t.display="block";for(var c=this.banner.getElementsByTagName("a"),s=0;s<c.length;s++)c[s].style.color="#333"},t.prototype._addListeners=function(){for(var t=this.banner.getElementsByTagName("button"),e=0;e<t.length;e++)t[e].addEventListener("click",this._onButtonClick.bind(this))},t.prototype._onButtonClick=function(t){var e={},n=t.target.className;if(-1!=n.indexOf("cyn-btn-accept-all"))for(var i in this._config.categories)e[i]=!0;else{if(-1==n.indexOf("cyn-btn-save"))return;for(var o=this.banner.getElementsByTagName("input"),c=0;c<o.length;c++)"checkbox"==o[c].type&&(e[o[c].value]=o[c].checked)}this.hide(),this._runListeners(e),this._save(e)},t.prototype._runListeners=function(e){var i=this,o=void 0===e;void 0===e&&(e=this.getSettings()),this._loopOverCategories(function(t,n){t.onChange.forEach(function(t){return t(e[n])}),!0===e[n]?(i._activateScriptsOfCategory(n),t.onAccept.forEach(function(t){return t()})):t.onReject.forEach(function(t){var e=t();o||!1===e||void 0!==i._config.categories[n].reloadOnReject&&!0!==i._config.categories[n].reloadOnReject||location.reload()})})},t.prototype._loopOverCategories=function(t){for(var e in this._config.categories)t(this._config.categories[e],e)},t.prototype._insertLinks=function(t){return null!=this._config.cookiePolicy&&(t=t.replace("COOKIE_POLICY",this._createLink(this._config.cookiePolicy))),null!=this._config.privacyPolicy&&(t=t.replace("PRIVACY_POLICY",this._createLink(this._config.privacyPolicy))),null!=this._config.imprint&&(t=t.replace("IMPRINT",this._createLink(this._config.imprint))),t},t.prototype._createLink=function(t){return'<a href="'+t.url+'">'+t.text+"</a>"},t.prototype._activateScriptsOfCategory=function(t){document.querySelectorAll("script[data-cyn-require="+t+"]").forEach(function(t){var e;void 0===t.dataset.cynDone&&(t.dataset.cynDone=!0,e=document.createElement("script"),null==t.dataset.cynSrc?e.innerText=t.innerText:e.src=t.dataset.cynSrc,document.body.appendChild(e))})},t.prototype.show=function(){this.banner.style.display="block"},t.prototype.hide=function(){this.banner.style.display="none"},t}(); | ||
var CookieYesNo=function(){"use strict"; | ||
/** | ||
* @license | ||
* CookieYesNo | https://github.com/philippG777/cookieyesno | BSD 4-Clause License (Modified) | ||
* Copyright (c) 2021 Philipp Gretzl | ||
*/function t(t){var i=this;function e(t,e){void 0===i._config[t]&&(i._config[t]=e)}this.version="1.1.1",this.cookie={set:function(t){var e=new Date;e.setTime(e.getTime()+7776e6),document.cookie="_cyn="+t+";expires="+e.toUTCString()+";path=/;SameSite=Lax"},get:function(){for(var t=document.cookie.split(";"),e=0;e<t.length;e++){var i=t[e].trim().split("=");if("_cyn"==i[0])return i[1]}return null},clear:function(){document.cookie="_cyn=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;SameSite=Lax"}},window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),this._config=t,e("title","Cookie Settings"),e("acceptAllButtonText","Accept all cookies"),e("acceptSelectionButtonText","Accept selected cookies");var n=["onAccept","onReject","onChange"];this._loopOverCategories(function(e){n.forEach(function(t){void 0===e[t]&&(e[t]=[])})}),this.banner=this._createBanner(),this._applyStyle(),this._addListeners();var o=this._load();null==o?this.show():o.version!=this.version||null!=this._config.version&&this._config.version!=o.configversion?(this.cookie.clear(),this.show()):this._runListeners()}return t.prototype._load=function(){var t=this.cookie.get();return null==t?null:JSON.parse(t)},t.prototype._save=function(t){var e={version:this.version,settings:t};null!=this._config.version&&(e.configversion=this._config.version),this.cookie.set(JSON.stringify(e))},t.prototype.getSettings=function(){var t=this._load();return null==t?{}:t.settings},t.prototype.onChange=function(t,e){this._config.categories[t].onChange.push(e)},t.prototype.onAccept=function(t,e){!0===this.getSettings()[t]&&e(),this._config.categories[t].onAccept.push(e)},t.prototype.onReject=function(t,e){!1===this.getSettings()[t]&&e(),this._config.categories[t].onReject.push(e)},t.prototype.reviewSettings=function(){this._bannerApplySettings(this.getSettings()),this.show()},t.prototype._createBanner=function(){var t=null!=this._config.text&&null!=this._config.text.above?this._config.text.above:'This website uses cookies.You can choose below which cookies may be stored on your device. You can allow all cookies usingthe "Accept all cookies" button or accept a selection of cookies by using the"Accept selected cookies" button and the checkboxes to select cookie categories.You can review and revoke consent at any time using the "Review cookie settings" link in the footer.',e=null!=this._config.text&&null!=this._config.text.below?this._config.text.below:"",i=document.createElement("div");i.className="cyn-banner";var n='<h3 style="font-size:28px;font-weight:bold;margin-top:16px;margin-bottom:20px">'+this._config.title+"</h3>";return n+="<p>"+this._insertLinks(t)+"</p>",n+='<button class="cyn-btn-accept-all">'+this._config.acceptAllButtonText+"</button>",n+='<button class="cyn-btn-save">'+this._config.acceptSelectionButtonText+"</button>",n+='<table class="cyn-categories"><tbody>',this._loopOverCategories(function(t,e){n+='<tr><td style="font-weight:bold">'+t.name+"</td><td>"+t.description+"</td><td>",n+='<input type="checkbox" value="'+e+'"'+(t.accepted?" checked":"")+(!0===t.changeable||void 0===t.changeable?"":" disabled")+"/>",n+="</td></tr>"}),n+="</tbody></table>",n+="<p>"+this._insertLinks(e)+"</p>",n+='<div class="cyn-other-links" style="padding-top:6px;padding-bottom:8px;font-size:12px">',null!=this._config.imprint&&(n+=this._createLink(this._config.imprint)+" "),null!=this._config.privacyPolicy&&(n+=this._createLink(this._config.privacyPolicy)+" "),null!=this._config.cookiePolicy&&(n+=this._createLink(this._config.cookiePolicy)),n+="</div>",i.innerHTML=n,i.style.display="none",document.body.appendChild(i),i},t.prototype._bannerApplySettings=function(t){for(var e=this.banner.getElementsByTagName("input"),i=0;i<e.length;i++)"checkbox"==e[i].type&&(e[i].checked=null!=t[e[i].value]&&1==t[e[i].value])},t.prototype._applyStyle=function(){var t=this.banner.style;t.zIndex=5e3,t.backgroundColor="#fff",t.position="fixed",t.padding="16px",t.boxShadow="0 0 24px #aaa",t.borderRadius="8px",t.fontSize="14px",t.fontFamily='"Trebuchet MS", Helvetica, sans-serif',t.color="#444",t.overflowY="auto",window.innerWidth<=768?(t.top=t.right=t.left=t.bottom="16px",t.maxWidth="80%"):(t.right=t.bottom="32px",t.maxHeight="80vh",t.maxWidth="40%"),(t=this.banner.getElementsByTagName("table")[0].style).margin="16px";for(var e=this.banner.getElementsByTagName("td"),i=0;i<e.length;i++)e[i].style.padding="8px";for(var n=this.banner.getElementsByTagName("button"),o=0;o<n.length;o++)(t=n[o].style).boxSizing="border-box",t.cursor="pointer",t.margin="12px",t.marginLeft="10%",t.borderRadius="4px",t.border="0px",t.backgroundColor="#48c774",t.color="white",t.fontSize="18px",t.padding="8px",t.paddingLeft=t.paddingRight="12px",t.display="block";for(var c=this.banner.getElementsByTagName("a"),s=0;s<c.length;s++)c[s].style.color="#333"},t.prototype._addListeners=function(){for(var t=this.banner.getElementsByTagName("button"),e=0;e<t.length;e++)t[e].addEventListener("click",this._onButtonClick.bind(this))},t.prototype._onButtonClick=function(t){var e={},i=t.target.className;if(-1!=i.indexOf("cyn-btn-accept-all"))for(var n in this._config.categories)e[n]=!0;else{if(-1==i.indexOf("cyn-btn-save"))return;for(var o=this.banner.getElementsByTagName("input"),c=0;c<o.length;c++)"checkbox"==o[c].type&&(e[o[c].value]=o[c].checked)}this.hide(),this._runListeners(e),this._save(e)},t.prototype._runListeners=function(e){var n=this,o=void 0===e;void 0===e&&(e=this.getSettings()),this._loopOverCategories(function(t,i){t.onChange.forEach(function(t){return t(e[i])}),!0===e[i]?(n._activateScriptsOfCategory(i),t.onAccept.forEach(function(t){return t()})):t.onReject.forEach(function(t){var e=t();o||!1===e||void 0!==n._config.categories[i].reloadOnReject&&!0!==n._config.categories[i].reloadOnReject||location.reload()})})},t.prototype._loopOverCategories=function(t){for(var e in this._config.categories)t(this._config.categories[e],e)},t.prototype._insertLinks=function(t){return null!=this._config.cookiePolicy&&(t=t.replace("COOKIE_POLICY",this._createLink(this._config.cookiePolicy))),null!=this._config.privacyPolicy&&(t=t.replace("PRIVACY_POLICY",this._createLink(this._config.privacyPolicy))),null!=this._config.imprint&&(t=t.replace("IMPRINT",this._createLink(this._config.imprint))),t},t.prototype._createLink=function(t){return'<a href="'+t.url+'">'+t.text+"</a>"},t.prototype._activateScriptsOfCategory=function(t){document.querySelectorAll("script[data-cyn-require="+t+"]").forEach(function(t){var e;void 0===t.dataset.cynDone&&(t.dataset.cynDone=!0,e=document.createElement("script"),null==t.dataset.cynSrc?e.innerText=t.innerText:e.src=t.dataset.cynSrc,document.body.appendChild(e))})},t.prototype.show=function(){this.banner.style.display="block"},t.prototype.hide=function(){this.banner.style.display="none"},t}(); |
{ | ||
"name": "cookieyesno", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"main": "dist/cookieyesno.cjs.js", | ||
@@ -30,3 +30,3 @@ "module": "src/cookieyesno.js", | ||
"rollup-plugin-uglify": "^6.0.4", | ||
"serve": "^11.0.2" | ||
"serve": "^11.3.2" | ||
}, | ||
@@ -33,0 +33,0 @@ "dependencies": {}, |
@@ -50,3 +50,7 @@ import resolve from '@rollup/plugin-node-resolve'; | ||
buble(), | ||
uglify() | ||
uglify({ | ||
output: { | ||
comments: "some" | ||
} | ||
}) | ||
] | ||
@@ -53,0 +57,0 @@ }, |
'use strict'; | ||
/*! | ||
CookieYesNo | philippG777 | https://github.com/philippG777/cookieyesno | MIT License | ||
/** | ||
* @license | ||
* CookieYesNo | https://github.com/philippG777/cookieyesno | BSD 4-Clause License (Modified) | ||
* Copyright (c) 2021 Philipp Gretzl | ||
*/ | ||
// TODO: | ||
// Load blocked scripts | ||
// reload on reject (by default true) none | ||
export default class CookieYesNo { | ||
constructor(config) { | ||
this.version = '1.1.0'; | ||
this.version = '1.1.1'; | ||
this.cookie = { // cookie handler | ||
@@ -33,2 +31,7 @@ set: function(data) { | ||
}; | ||
// IE polyfill | ||
if (window.NodeList && !NodeList.prototype.forEach) { | ||
NodeList.prototype.forEach = Array.prototype.forEach; | ||
} | ||
@@ -122,7 +125,7 @@ this._config = config; | ||
const textAbove = (this._config.text != undefined && this._config.text.above != undefined)? | ||
this._config.text.above : 'This website uses cookies.\ | ||
You can choose below which cookies may be stored on your device. You can allow all cookies using\ | ||
the "Accept all cookies" button or accept a selection of cookies by using the\ | ||
"Accept selected cookies" button and the checkboxes to select cookie categories.\ | ||
You can review and revoke consent at any time using the "Review cookie settings" link in the footer.'; | ||
this._config.text.above : 'This website uses cookies.' + | ||
'You can choose below which cookies may be stored on your device. You can allow all cookies using' + | ||
'the "Accept all cookies" button or accept a selection of cookies by using the' + | ||
'"Accept selected cookies" button and the checkboxes to select cookie categories.' + | ||
'You can review and revoke consent at any time using the "Review cookie settings" link in the footer.'; | ||
@@ -129,0 +132,0 @@ const textBelow = (this._config.text != undefined && this._config.text.below != undefined)? |
176325
20
1459