simple-gdpr
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,1 +0,1 @@ | ||
!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():t.simplegdpr=e()}(this,function(){this.SimpleGDPR=function(t){this.active=!0;var e=this,s=document.createElement("span");s.innerText="We use browser cookies to personalize content and Ads, to provide social media features and analyse traffic. To use our site, you must agree to our ";var i=document.createElement("a");i.innerText="Privacy Policy.",i.className="sgdpr-policy";var n=document.createElement("span");n.appendChild(s),n.appendChild(i);var o={title:"Cookies & Privacy Policy",message:n,link:null,icons:!0,theme:"light",animation:"fade",float:"bottom-right",callback:function(){e.close()},openOnInit:!0};this.opts=function(){for(var t=1;t<arguments.length;t++)for(var e in arguments[t])arguments[t].hasOwnProperty(e)&&(arguments[0][e]=arguments[t][e]);return arguments[0]}({},o,t),this.init()},SimpleGDPR.prototype.init=function(){(function(){var t=document.createElement("div");t.className="sgdpr-box",!(t.id="sgdpr-box")===this.opts.openOnInit&&(t.style.display="none");var e=document.createElement("div");e.id="sgdpr-title-container";var s=document.createElement("div");s.className="sgdpr-title",s.innerText=this.opts.title;var i=document.createElement("div");if(i.className="sgdpr-message","string"==typeof this.opts.message)i.innerText=this.opts.message,null!==this.opts.link&&console.warn("SimpleGDPR: Link will not work when message property is passed as a String.");else if(this.opts.message instanceof HTMLElement&&(i.appendChild(this.opts.message),null!==this.opts.link))if("string"==typeof this.opts.link||"function"==typeof this.opts.link){var n=i.getElementsByTagName("a");if(0<n.length)for(var o=0;o<n.length;o++)n[o].classList.contains("sgdpr-policy")&&("string"==typeof this.opts.link?n[o].href=this.opts.link:"function"==typeof this.opts.link&&n[o].addEventListener("click",this.opts.link))}else console.warn("SimpleGDPR: You can only pass Strings or Functions into the link property.");var a=document.createElement("button");a.className="sgdpr-button",a.id="sgdpr-button";var d=document.createElement("div");d.className="sgdpr-text",d.innerText="Agree";var l=document.createElement("div");if(l.className="sgdpr-yes-mobile",this.opts.icons){var r=document.createElement("div");r.className="sgdpr-info-icon",r.id="sgdpr-info-icon","dark"==this.opts.theme&&r.classList.add("sgdpr-info-icon-dark"),e.appendChild(r)}if(e.appendChild(s),a.appendChild(d),a.appendChild(l),t.appendChild(e),t.appendChild(i),t.appendChild(a),function(t,e,s,i,n){var o=this.opts.theme.toLowerCase(),a=this.opts.float.toLowerCase();switch(this.opts.icons&&(e.style.paddingLeft="5px",n.style.paddingRight="5px"),o){case"light":t.classList.add("sgdpr-box-light"),i.classList.add("sgdpr-button-light");break;case"modern":t.classList.add("sgdpr-box-modern"),i.classList.add("sgdpr-button-modern");break;case"dark":t.classList.add("sgdpr-box-dark"),i.classList.add("sgdpr-button-dark");break;case"material":t.classList.add("sgdpr-box-material"),i.classList.add("sgdpr-button-material"),e.classList.add("sgdpr-title-material")}switch(a){case"bottom-right":t.classList.add("sgdpr-bottom-right");break;case"bottom-left":t.classList.add("sgdpr-bottom-left");break;case"top-right":t.classList.add("sgdpr-top-right");break;case"top-left":t.classList.add("sgdpr-top-left")}}.call(this,t,s,i,a,d),this.opts.icons){var p=document.createElement("div");p.className="sgdpr-yes-icon",a.appendChild(p)}document.body.prepend(t),a.addEventListener("click",this.opts.callback)}).call(this)},SimpleGDPR.prototype.isActive=function(){return this.active},SimpleGDPR.prototype.close=function(){var t=document.getElementById("sgdpr-box");"slide"===this.opts.animation?(t.classList.add("sgdpr-slideout"),setTimeout(function(){t.style.display="none",t.classList.remove("sgdpr-slideout")},500)):"fade"!==this.opts.animation&&!0!==this.opts.animation||(t.classList.add("sgdpr-fadeout"),setTimeout(function(){t.style.display="none",t.classList.remove("sgdpr-fadeout")},500)),this.active=!1},SimpleGDPR.prototype.open=function(){var t=document.getElementById("sgdpr-box");t.style.display="","slide"===this.opts.animation?(t.classList.add("sgdpr-slidein"),setTimeout(function(){t.classList.remove("sgdpr-slidein")},500)):"fade"!==this.opts.animation&&!0!==this.opts.animation||(t.classList.add("sgdpr-fadein"),setTimeout(function(){t.classList.remove("sgdpr-fadein")},500)),this.active=!0},SimpleGDPR.prototype.destroy=function(){var t=document.getElementById("sgdpr-box");t.parentElement.removeChild(t)},SimpleGDPR.prototype.setContent=function(t){for(var e=document.getElementById("sgdpr-box");e.firstChild;)e.removeChild(e.firstChild);t instanceof HTMLElement?e.appendChild(t):console.warn("SimpleGDPR: setContent can only take HTMLElement objects.")},SimpleGDPR.prototype.setCallback=function(t){var e=document.getElementById("sgdpr-button");null!==e?"function"==typeof t?(e.removeEventListener("click",this.opts.callback),e.addEventListener("click",t)):console.warn("setCallback() must receive a function."):console.warn("setCallback() button not found. This function will not work if setContent() was called.")}}); | ||
!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():t.simplegdpr=e()}(this,function(){function c(t,e){"bottom-right"===e?(t.classList.add("sgdpr-bottom-right"),document.body.prepend(t)):"bottom-left"===e?(t.classList.add("sgdpr-bottom-left"),document.body.prepend(t)):"top-right"===e?(t.classList.add("sgdpr-top-right"),document.body.prepend(t)):"top-left"===e?(t.classList.add("sgdpr-top-left"),document.body.prepend(t)):document.addEventListener("DOMContentLoaded",function(){try{document.getElementById(e).appendChild(t)}catch(t){console.error("Element with id "+e+" not found. "+e,t.message)}})}this.SimpleGDPR=function(t){this.active=!0;var e=this,s={title:"Cookies & Privacy Policy",message:function(){var t=document.createElement("span");t.innerText="We use browser cookies to personalize content and Ads, to provide social media features and analyse traffic. To use our site, you must agree to our ";var e=document.createElement("a");e.innerText="Privacy Policy.",e.className="sgdpr-policy";var s=document.createElement("span");return s.appendChild(t),s.appendChild(e),s}.call(this),link:null,icons:!0,theme:"light",animation:"fade",float:"bottom-right",callback:function(){e.close()},openOnInit:!0,id:{button:null,box:null}};this.opts=function(){for(var t=1;t<arguments.length;t++)for(var e in arguments[t])arguments[t].hasOwnProperty(e)&&(arguments[0][e]=arguments[t][e]);return arguments[0]}({},s,t),function(){var t=document.createElement("div");t.className="sgdpr-box",null!==this.opts.id.box&&"string"==typeof this.opts.id.box?t.id=this.opts.id.box:t.id="sgdpr-box";!1===this.opts.openOnInit&&(t.style.display="none");var e=document.createElement("div");e.id="sgdpr-title-container";var s=document.createElement("div");s.className="sgdpr-title",s.innerText=this.opts.title;var o=document.createElement("div");if(o.className="sgdpr-message","string"==typeof this.opts.message)o.innerText=this.opts.message,null!==this.opts.link&&console.warn("SimpleGDPR: Link will not work when message property is passed as a String.");else if(this.opts.message instanceof HTMLElement&&(o.appendChild(this.opts.message),null!==this.opts.link))if("string"==typeof this.opts.link||"function"==typeof this.opts.link){var i=o.getElementsByTagName("a");if(0<i.length)for(var n=0;n<i.length;n++)i[n].classList.contains("sgdpr-policy")&&("string"==typeof this.opts.link?i[n].href=this.opts.link:"function"==typeof this.opts.link&&i[n].addEventListener("click",this.opts.link))}else console.warn("SimpleGDPR: You can only pass Strings or Functions into the link property.");var d=document.createElement("button");d.className="sgdpr-button",null!==this.opts.id.button&&"string"==typeof this.opts.id.button?d.id=this.opts.id.button:d.id="sgdpr-button";var a=document.createElement("div");a.className="sgdpr-text",a.innerText="Agree";var l=document.createElement("div");if(l.className="sgdpr-yes-mobile",this.opts.icons){var p=document.createElement("div");p.className="sgdpr-info-icon",p.id="sgdpr-info-icon","dark"==this.opts.theme&&p.classList.add("sgdpr-info-icon-dark"),e.appendChild(p)}if(e.appendChild(s),d.appendChild(a),d.appendChild(l),t.appendChild(e),t.appendChild(o),t.appendChild(d),function(t,e,s,o,i){var n=this.opts.theme.toLowerCase();switch(this.opts.float.toLowerCase(),this.opts.icons&&(e.style.paddingLeft="5px",i.style.paddingRight="5px"),n){case"light":t.classList.add("sgdpr-box-light"),o.classList.add("sgdpr-button-light");break;case"modern":t.classList.add("sgdpr-box-modern"),o.classList.add("sgdpr-button-modern");break;case"dark":t.classList.add("sgdpr-box-dark"),o.classList.add("sgdpr-button-dark");break;case"material":t.classList.add("sgdpr-box-material"),o.classList.add("sgdpr-button-material"),e.classList.add("sgdpr-title-material")}}.call(this,t,s,o,d,a),c.call(this,t,this.opts.float),this.opts.icons){var r=document.createElement("div");r.className="sgdpr-yes-icon",d.appendChild(r)}d.addEventListener("click",this.opts.callback)}.call(this)},SimpleGDPR.prototype.isActive=function(){return this.active},SimpleGDPR.prototype.close=function(){var t;t=null!==this.opts.id.box&&"string"==typeof this.opts.id.box?document.getElementById(this.opts.id.box):document.getElementById("sgdpr-box"),"slide"===this.opts.animation?(t.classList.add("sgdpr-slideout"),setTimeout(function(){t.style.display="none",t.classList.remove("sgdpr-slideout")},500)):"fade"!==this.opts.animation&&!0!==this.opts.animation||(t.classList.add("sgdpr-fadeout"),setTimeout(function(){t.style.display="none",t.classList.remove("sgdpr-fadeout")},500)),this.active=!1},SimpleGDPR.prototype.open=function(){var t;(t=null!==this.opts.id.box&&"string"==typeof this.opts.id.box?document.getElementById(this.opts.id.box):document.getElementById("sgdpr-box")).style.display="","slide"===this.opts.animation?(t.classList.add("sgdpr-slidein"),setTimeout(function(){t.classList.remove("sgdpr-slidein")},500)):"fade"!==this.opts.animation&&!0!==this.opts.animation||(t.classList.add("sgdpr-fadein"),setTimeout(function(){t.classList.remove("sgdpr-fadein")},500)),this.active=!0},SimpleGDPR.prototype.destroy=function(){var t=document.getElementById("sgdpr-box");t.parentElement.removeChild(t)},SimpleGDPR.prototype.setContent=function(t){for(var e=document.getElementById("sgdpr-box");e.firstChild;)e.removeChild(e.firstChild);t instanceof HTMLElement?e.appendChild(t):console.warn("SimpleGDPR: setContent can only take HTMLElement objects.")},SimpleGDPR.prototype.setCallback=function(t){var e=document.getElementById("sgdpr-button");null!==e?"function"==typeof t?(e.removeEventListener("click",this.opts.callback),e.addEventListener("click",t)):console.warn("setCallback() must receive a function."):console.warn("setCallback() button not found. This function will not work if setContent() was called.")},SimpleGDPR.prototype.relocate=function(e){document.addEventListener("DOMContentLoaded",function(){var t=document.getElementById("sgdpr-box");t.classList.remove("sgdpr-bottom-right","sgdpr-bottom-left","sgdpr-top-right","sgdpr-top-left"),c.call(this,t,e)})},SimpleGDPR.prototype.appendTo=function(e){document.addEventListener("DOMContentLoaded",function(){var t=document.getElementById("sgdpr-box");t.classList.remove("sgdpr-bottom-right","sgdpr-bottom-left","sgdpr-top-right","sgdpr-top-left"),document.getElementById(e).appendChild(t)})}}); |
{ | ||
"name": "simple-gdpr", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "lightweight and simple gdpr solution", | ||
@@ -5,0 +5,0 @@ "main": "dist/simplegdpr.min.js", |
@@ -14,13 +14,6 @@ (function (root, factory) { | ||
this.active = true; | ||
var self = this; | ||
var defaultGroup = buildDefaultMessage.call(this); | ||
var defaultMessage = document.createElement('span'); | ||
defaultMessage.innerText = 'We use browser cookies to personalize content and Ads, to provide social media features and analyse traffic. To use our site, you must agree to our '; | ||
var defaultPolicy = document.createElement('a'); | ||
defaultPolicy.innerText = 'Privacy Policy.'; | ||
defaultPolicy.className = 'sgdpr-policy'; | ||
var defaultGroup = document.createElement('span'); | ||
defaultGroup.appendChild(defaultMessage); | ||
defaultGroup.appendChild(defaultPolicy); | ||
var defaults = { | ||
@@ -38,2 +31,6 @@ title: 'Cookies & Privacy Policy', | ||
openOnInit: true, | ||
id: { | ||
button: null, | ||
box: null, | ||
}, | ||
} | ||
@@ -43,7 +40,2 @@ // Need to add Polyfill for IE11. | ||
this.init(); | ||
} | ||
SimpleGDPR.prototype.init = function () { | ||
build.call(this); | ||
@@ -57,4 +49,11 @@ } | ||
SimpleGDPR.prototype.close = function () { | ||
var b = document.getElementById('sgdpr-box'); | ||
var b; | ||
if (this.opts.id.box !== null && typeof this.opts.id.box === 'string') { | ||
b = document.getElementById(this.opts.id.box); | ||
} else { | ||
b = document.getElementById('sgdpr-box'); | ||
} | ||
if (this.opts.animation === 'slide') { | ||
@@ -66,4 +65,3 @@ b.classList.add('sgdpr-slideout'); | ||
}, 500); | ||
} | ||
else if (this.opts.animation === 'fade' || this.opts.animation === true) { | ||
} else if (this.opts.animation === 'fade' || this.opts.animation === true) { | ||
b.classList.add('sgdpr-fadeout'); | ||
@@ -79,3 +77,11 @@ setTimeout(function () { | ||
SimpleGDPR.prototype.open = function () { | ||
var b = document.getElementById('sgdpr-box'); | ||
var b; | ||
if (this.opts.id.box !== null && typeof this.opts.id.box === 'string') { | ||
b = document.getElementById(this.opts.id.box); | ||
} else { | ||
b = document.getElementById('sgdpr-box'); | ||
} | ||
b.style.display = ''; | ||
@@ -88,4 +94,3 @@ | ||
}, 500); | ||
} | ||
else if (this.opts.animation === 'fade' || this.opts.animation === true) { | ||
} else if (this.opts.animation === 'fade' || this.opts.animation === true) { | ||
b.classList.add('sgdpr-fadein'); | ||
@@ -95,3 +100,3 @@ setTimeout(function () { | ||
}, 500); | ||
} | ||
} | ||
this.active = true; | ||
@@ -123,8 +128,6 @@ } | ||
b.addEventListener('click', f); | ||
} | ||
else { | ||
} else { | ||
console.warn('setCallback() must receive a function.'); | ||
} | ||
} | ||
else { | ||
} else { | ||
console.warn('setCallback() button not found. This function will not work if setContent() was called.'); | ||
@@ -134,7 +137,41 @@ } | ||
SimpleGDPR.prototype.relocate = function (f) { | ||
document.addEventListener("DOMContentLoaded", function () { | ||
var box = document.getElementById('sgdpr-box'); | ||
box.classList.remove('sgdpr-bottom-right', 'sgdpr-bottom-left', 'sgdpr-top-right', 'sgdpr-top-left'); | ||
floatHandler.call(this, box, f); | ||
}); | ||
} | ||
SimpleGDPR.prototype.appendTo = function (el) { | ||
document.addEventListener("DOMContentLoaded", function () { | ||
var box = document.getElementById('sgdpr-box'); | ||
box.classList.remove('sgdpr-bottom-right', 'sgdpr-bottom-left', 'sgdpr-top-right', 'sgdpr-top-left'); | ||
var parent = document.getElementById(el); | ||
parent.appendChild(box); | ||
}) | ||
} | ||
function buildDefaultMessage() { | ||
var message = document.createElement('span'); | ||
message.innerText = 'We use browser cookies to personalize content and Ads, to provide social media features and analyse traffic. To use our site, you must agree to our '; | ||
var policy = document.createElement('a'); | ||
policy.innerText = 'Privacy Policy.'; | ||
policy.className = 'sgdpr-policy'; | ||
var group = document.createElement('span'); | ||
group.appendChild(message); | ||
group.appendChild(policy); | ||
return group; | ||
} | ||
function build() { | ||
var box = document.createElement('div'); | ||
box.className = 'sgdpr-box'; | ||
box.id = 'sgdpr-box'; | ||
if (this.opts.id.box !== null && typeof this.opts.id.box === 'string') { | ||
box.id = this.opts.id.box; | ||
} else { | ||
box.id = 'sgdpr-box'; | ||
} | ||
if (this.opts.openOnInit === false) { | ||
@@ -171,6 +208,5 @@ box.style.display = 'none'; | ||
els[i].href = this.opts.link; | ||
} else if (typeof this.opts.link === 'function') { | ||
els[i].addEventListener('click', this.opts.link); | ||
} | ||
else if (typeof this.opts.link === 'function') { | ||
els[i].addEventListener('click', this.opts.link); | ||
} | ||
} | ||
@@ -183,8 +219,13 @@ } | ||
} | ||
} | ||
} | ||
var button = document.createElement('button'); | ||
button.className = 'sgdpr-button'; | ||
button.id = 'sgdpr-button'; | ||
if (this.opts.id.button !== null && typeof this.opts.id.button === 'string') { | ||
button.id = this.opts.id.button; | ||
} else { | ||
button.id = 'sgdpr-button'; | ||
} | ||
// add option | ||
@@ -216,2 +257,3 @@ var text = document.createElement('div'); | ||
styleHandler.call(this, box, title, msg, button, text); | ||
floatHandler.call(this, box, this.opts.float); | ||
@@ -224,6 +266,3 @@ if (this.opts.icons) { | ||
document.body.prepend(box); | ||
button.addEventListener('click', this.opts.callback); | ||
} | ||
@@ -262,21 +301,28 @@ | ||
} | ||
switch (float) { | ||
case 'bottom-right': | ||
box.classList.add('sgdpr-bottom-right'); | ||
break; | ||
case 'bottom-left': | ||
box.classList.add('sgdpr-bottom-left'); | ||
break; | ||
case 'top-right': | ||
box.classList.add('sgdpr-top-right'); | ||
break; | ||
case 'top-left': | ||
box.classList.add('sgdpr-top-left'); | ||
break; | ||
case 'top-center': | ||
break; | ||
case 'bottom-center': | ||
break; | ||
case 'center': | ||
break; | ||
} | ||
function floatHandler(box, f) { | ||
// Add support for top-center, bottom-center, and center; | ||
if (f === 'bottom-right') { | ||
box.classList.add('sgdpr-bottom-right'); | ||
document.body.prepend(box); | ||
} else if (f === 'bottom-left') { | ||
box.classList.add('sgdpr-bottom-left'); | ||
document.body.prepend(box); | ||
} else if (f === 'top-right') { | ||
box.classList.add('sgdpr-top-right'); | ||
document.body.prepend(box); | ||
} else if (f === 'top-left') { | ||
box.classList.add('sgdpr-top-left'); | ||
document.body.prepend(box); | ||
} else { | ||
document.addEventListener("DOMContentLoaded", function () { | ||
try { | ||
var el = document.getElementById(f); | ||
el.appendChild(box); | ||
} catch (e) { | ||
console.error('Element with id ' + f + ' not found. ' + f, e.message); | ||
} | ||
}); | ||
} | ||
@@ -283,0 +329,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
45103
8
594
1