|
@ -1,5 +1,5 @@ |
|
|
<tiny-consent> |
|
|
<tiny-consent> |
|
|
<div id="tiny-consent" class={ state.isOpen === true ? 'tiny-consent show' : 'tiny-consent' }> |
|
|
|
|
|
|
|
|
<div id="tiny-consent" class="tiny-consent"> |
|
|
<div class="tiny-consent__inner"> |
|
|
<div class="tiny-consent__inner"> |
|
|
<div class="tiny-consent__header"> |
|
|
<div class="tiny-consent__header"> |
|
|
<h3 class="tiny_consent__title"> |
|
|
<h3 class="tiny_consent__title"> |
|
@ -16,32 +16,43 @@ |
|
|
</div> |
|
|
</div> |
|
|
<div class="tiny-consent__main"> |
|
|
<div class="tiny-consent__main"> |
|
|
<ul class="tiny-consent__cookies"> |
|
|
<ul class="tiny-consent__cookies"> |
|
|
<li class={ state.hasChanged && cookie.hasConsent === true ? 'tiny-consent__cookie' : 'tiny-consent__cookie show' } each={ (cookie, index) in props.cookies }> |
|
|
|
|
|
<div class="tiny-consent__cookie-content"> |
|
|
|
|
|
<p> |
|
|
|
|
|
<span if={ cookie.title } class="tiny-consent__cookie-title">{ cookie.title }</span> |
|
|
|
|
|
{ cookie.content } |
|
|
|
|
|
</p> |
|
|
|
|
|
<div class="tiny-consent__cookie-footer"> |
|
|
|
|
|
<ul> |
|
|
|
|
|
<li if={ cookie.provider }><span>{ state.options.text.footer__provider }</span> { cookie.provider }</li> |
|
|
|
|
|
<li if={ cookie.name }><span>{ state.options.text.footer__name }</span> { cookie.name }</li> |
|
|
|
|
|
<li if={ cookie.duration }><span>{ state.options.text.footer__duration }</span> { cookie.duration }</li> |
|
|
|
|
|
<li if={ cookie.privacy_policy }><a href="{ cookie.privacy_policy }">{ state.options.text.footer__url }</a></li> |
|
|
|
|
|
</ul> |
|
|
|
|
|
|
|
|
<li class="tiny-consent__cookie-group" each={ group in Object.entries(state.cookies) }> |
|
|
|
|
|
<header class="tiny-consent__cookie-accordion-header" if={ group[0] === 'default' && group[1].length > 1 } onclick={ (event) => { handleToogle(event) }}> |
|
|
|
|
|
{ state.options.text.title__default } ({ group[1].length }) <span class="tiny-consent__cookie-accordion-header-icon">▲</span> |
|
|
|
|
|
</header> |
|
|
|
|
|
<div class="tiny-consent__cookie-accordion{ group[0] === 'default' && group[1].length > 1 ? ' tiny-consent__cookie-accordion--active' : '' }"> |
|
|
|
|
|
<div class="tiny-consent__cookie-accordion-inner"> |
|
|
|
|
|
<div class="tiny-consent__cookie-wrapper" each={ (cookie, index) in group[1] }> |
|
|
|
|
|
<div class="tiny-consent__cookie-content"> |
|
|
|
|
|
<p> |
|
|
|
|
|
<span if={ cookie.title } class="tiny-consent__cookie-title">{ cookie.title }</span> |
|
|
|
|
|
{ cookie.content } |
|
|
|
|
|
</p> |
|
|
|
|
|
<div class="tiny-consent__cookie-footer"> |
|
|
|
|
|
<ul> |
|
|
|
|
|
<li if={ cookie.provider }><span>{ state.options.text.footer__provider }</span> { cookie.provider }</li> |
|
|
|
|
|
<li if={ cookie.name }><span>{ state.options.text.footer__name }</span> { cookie.name }</li> |
|
|
|
|
|
<li if={ cookie.duration }><span>{ state.options.text.footer__duration }</span> { cookie.duration }</li> |
|
|
|
|
|
<li if={ cookie.privacy_policy }><a href="{ cookie.privacy_policy }">{ state.options.text.footer__url }</a></li> |
|
|
|
|
|
</ul> |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div if={ group[0] === 'other' } class="tiny-consent__cookie-decision"> |
|
|
|
|
|
<button class={ getAgreeClasses(cookie) } onclick={ (event) => { handleAgree(event, cookie, index) }}> |
|
|
|
|
|
{ state.options.text.button__agree } |
|
|
|
|
|
</button> |
|
|
|
|
|
<button if={ group[0] === 'other' } class={ getRejectClasses(cookie) } onclick={ (event) => { handleReject(event, cookie, index) }}> |
|
|
|
|
|
{ state.options.text.button__reject } |
|
|
|
|
|
</button> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div if={ group[0] === 'default' && index === (group[1].length - 1) } class="tiny-consent__cookie-decision"> |
|
|
|
|
|
<button disabled={ isOk() } class="button button--ok tiny-consent__button" onclick={ (event) => { handleDefault(event, cookies) }}> |
|
|
|
|
|
{ state.options.text.button__ok } |
|
|
|
|
|
</button> |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
<div class="tiny-consent__cookie-decision"> |
|
|
|
|
|
<button if={ !cookie.essential } class={ getAgreeClasses(cookie) } onclick={ (event) => { handleAgree(event, cookie, index) }}> |
|
|
|
|
|
{ state.options.text.button__agree } |
|
|
|
|
|
</button> |
|
|
|
|
|
<button if={ !cookie.essential } class={ getRejectClasses(cookie) } onclick={ (event) => { handleReject(event, cookie, index) }}> |
|
|
|
|
|
{ state.options.text.button__reject } |
|
|
|
|
|
</button> |
|
|
|
|
|
<button if={ cookie.essentialLast === true } disabled={ isOk() } class="button button--ok tiny-consent__button" onclick={ (event) => { handleOk(event, cookies) }}> |
|
|
|
|
|
{ state.options.text.button__ok } |
|
|
|
|
|
</button> |
|
|
|
|
|
</div> |
|
|
|
|
|
</li> |
|
|
</li> |
|
|
</ul> |
|
|
</ul> |
|
|
</div> |
|
|
</div> |
|
@ -54,6 +65,7 @@ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* tiny-consent.riot |
|
|
* tiny-consent.riot |
|
|
|
|
|
* <li class={ state.hasChanged && cookie.hasConsent === true ? 'tiny-consent__cookie' : 'tiny-consent__cookie show' } each={ (group, index) in state.cookies }> |
|
|
* |
|
|
* |
|
|
* @author Björn Hase |
|
|
* @author Björn Hase |
|
|
* @license http://opensource.org/licenses/MIT The MIT License |
|
|
* @license http://opensource.org/licenses/MIT The MIT License |
|
@ -74,6 +86,7 @@ |
|
|
text: { |
|
|
text: { |
|
|
title : 'Cookies', |
|
|
title : 'Cookies', |
|
|
content : 'We are using Cookies and display that was we use, also there are cookies you can accept or reject', |
|
|
content : 'We are using Cookies and display that was we use, also there are cookies you can accept or reject', |
|
|
|
|
|
title__default : 'Essential', |
|
|
button__agree : 'Yes', |
|
|
button__agree : 'Yes', |
|
|
button__reject : 'No', |
|
|
button__reject : 'No', |
|
|
button__ok : 'Ok', |
|
|
button__ok : 'Ok', |
|
@ -82,10 +95,14 @@ |
|
|
footer__provider: 'Provider', |
|
|
footer__provider: 'Provider', |
|
|
footer__duration: 'Cookie Duration', |
|
|
footer__duration: 'Cookie Duration', |
|
|
footer__privacy_policy: 'Privacy Policy' |
|
|
footer__privacy_policy: 'Privacy Policy' |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
offsetLineHeight: 1.15 |
|
|
}, |
|
|
}, |
|
|
isOpen: false, |
|
|
isOpen: false, |
|
|
hasChanged: false |
|
|
|
|
|
|
|
|
hasChanged: false, |
|
|
|
|
|
cookies: { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -145,6 +162,51 @@ |
|
|
return classes.join(' '); |
|
|
return classes.join(' '); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param {[type]} cookie [description] |
|
|
|
|
|
* @return {[type]} [description] |
|
|
|
|
|
*/ |
|
|
|
|
|
getWrapperClasses(cookie) |
|
|
|
|
|
{ |
|
|
|
|
|
let classes = [ |
|
|
|
|
|
'tiny-consent__wrapper' |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
if (data[cookie.id] === false) { |
|
|
|
|
|
classes.push('button--active'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return classes.join(' '); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* handle accordion, open and close |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
* @param {object} event |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
handleToogle(event) |
|
|
|
|
|
{ |
|
|
|
|
|
event.preventDefault(); |
|
|
|
|
|
|
|
|
|
|
|
let target = event.target; |
|
|
|
|
|
|
|
|
|
|
|
if (!event.target.nextElementSibling) { |
|
|
|
|
|
target = event.target.parentNode; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const height = target.nextElementSibling.childNodes[0].offsetHeight * this.state.options.offsetLineHeight; |
|
|
|
|
|
target.classList.toggle('tiny-consent__cookie-accordion-header--open'); |
|
|
|
|
|
|
|
|
|
|
|
if (!target.nextElementSibling.style.maxHeight) { |
|
|
|
|
|
target.nextElementSibling.style.maxHeight = height + 'px'; |
|
|
|
|
|
} else { |
|
|
|
|
|
target.nextElementSibling.style.maxHeight = ''; |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
|
* @return {Boolean} [description] |
|
|
* @return {Boolean} [description] |
|
@ -154,8 +216,8 @@ |
|
|
let data = this.getData(); |
|
|
let data = this.getData(); |
|
|
let result = true; |
|
|
let result = true; |
|
|
|
|
|
|
|
|
this.props.cookies.forEach((cookie) => { |
|
|
|
|
|
if (data[cookie.id] !== true && cookie.essential === true) { |
|
|
|
|
|
|
|
|
this.state.cookies.default.forEach((cookie) => { |
|
|
|
|
|
if (data[cookie.id] !== true) { |
|
|
result = false; |
|
|
result = false; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
@ -170,15 +232,28 @@ |
|
|
onMounted() |
|
|
onMounted() |
|
|
{ |
|
|
{ |
|
|
window.addEventListener('tiny-consent-open', () => { |
|
|
window.addEventListener('tiny-consent-open', () => { |
|
|
this.state.isOpen = true; |
|
|
|
|
|
this.state.hasChanged = false; |
|
|
|
|
|
|
|
|
this.root.firstChild.style.bottom = '0px'; |
|
|
this.update(); |
|
|
this.update(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// slide and set to visible |
|
|
|
|
|
this.root.firstChild.style.bottom = -(this.root.firstChild.offsetHeight) + 'px'; |
|
|
|
|
|
this.root.firstChild.style.visibility = 'visible'; |
|
|
|
|
|
|
|
|
|
|
|
window.requestAnimationFrame(() => { |
|
|
|
|
|
this.root.firstChild.classList.add('tiny-consent--animation'); |
|
|
|
|
|
if (this.state.hasChanged === true) { |
|
|
|
|
|
this.root.firstChild.style.bottom = '0px'; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
push() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
* |
|
|
* |
|
|
* |
|
|
*/ |
|
|
*/ |
|
@ -190,18 +265,13 @@ |
|
|
this.state.options = Object.assign(this.state.options, this.props.options); |
|
|
this.state.options = Object.assign(this.state.options, this.props.options); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// getting essential first |
|
|
|
|
|
this.props.cookies.sort(function(a, b) { |
|
|
|
|
|
return a['essential'] !== true; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// check if consent already has set |
|
|
// check if consent already has set |
|
|
if (Object.entries(data).length === 0) { |
|
|
if (Object.entries(data).length === 0) { |
|
|
this.state.hasChanged = true; |
|
|
this.state.hasChanged = true; |
|
|
this.state.isOpen = true; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.props.cookies.forEach((cookie, index) => { |
|
|
this.props.cookies.forEach((cookie, index) => { |
|
|
|
|
|
|
|
|
if (data[cookie.id] === true || data[cookie.id] === false) { |
|
|
if (data[cookie.id] === true || data[cookie.id] === false) { |
|
|
if (data[cookie.id] === true && cookie.handleAgree) { |
|
|
if (data[cookie.id] === true && cookie.handleAgree) { |
|
|
cookie.handleAgree(); |
|
|
cookie.handleAgree(); |
|
@ -209,16 +279,28 @@ |
|
|
cookie.handleReject(); |
|
|
cookie.handleReject(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.props.cookies[index].hasConsent = true; |
|
|
|
|
|
|
|
|
cookie.hasConsent = true; |
|
|
} else { |
|
|
} else { |
|
|
this.state.hasChanged = true; |
|
|
this.state.hasChanged = true; |
|
|
this.state.isOpen = true; |
|
|
|
|
|
|
|
|
cookie.hasConsent = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.props.cookies[index].hasConsent = false; |
|
|
|
|
|
|
|
|
// adding cookies to state |
|
|
|
|
|
if (cookie.default) { |
|
|
|
|
|
if (!this.state.cookies['default']) { |
|
|
|
|
|
this.state.cookies['default'] = []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.state.cookies['default'].push(cookie); |
|
|
|
|
|
} else { |
|
|
|
|
|
if (!this.state.cookies['other']) { |
|
|
|
|
|
this.state.cookies['other'] = []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.state.cookies['other'].push(cookie); |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.updateEssential(); |
|
|
|
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -243,21 +325,6 @@ |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @return {[type]} [description] |
|
|
|
|
|
*/ |
|
|
|
|
|
updateEssential() |
|
|
|
|
|
{ |
|
|
|
|
|
// set true for last essential cookie where consent is not already set |
|
|
|
|
|
for (let i = (this.props.cookies.length - 1); i >= 0; i--) { |
|
|
|
|
|
if ((this.state.hasChanged === true && this.props.cookies[i].hasConsent === false && this.props.cookies[i].essential === true) || (this.state.hasChanged === false && this.props.cookies[i].essential === true)) { |
|
|
|
|
|
this.props.cookies[i].essentialLast = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
|
* @param {[type]} event [description] |
|
|
* @param {[type]} event [description] |
|
@ -274,15 +341,16 @@ |
|
|
|
|
|
|
|
|
data[cookie.id] = true; |
|
|
data[cookie.id] = true; |
|
|
Cookie.set(this.state.options.cookie_name, data); |
|
|
Cookie.set(this.state.options.cookie_name, data); |
|
|
this.props.cookies[index].hasConsent = true; |
|
|
|
|
|
|
|
|
|
|
|
this.update(); |
|
|
this.update(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
|
* @param {[type]} event [description] |
|
|
|
|
|
* @return {[type]} [description] |
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
* |
|
|
|
|
|
* @param {object} event |
|
|
|
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
handleReject(event, cookie, index) { |
|
|
handleReject(event, cookie, index) { |
|
|
event.preventDefault(); |
|
|
event.preventDefault(); |
|
@ -295,43 +363,41 @@ |
|
|
|
|
|
|
|
|
data[cookie.id] = false; |
|
|
data[cookie.id] = false; |
|
|
Cookie.set(this.state.options.cookie_name, data); |
|
|
Cookie.set(this.state.options.cookie_name, data); |
|
|
this.props.cookies[index].hasConsent = true; |
|
|
|
|
|
|
|
|
|
|
|
this.update(); |
|
|
this.update(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
* setting default cookies |
|
|
* |
|
|
* |
|
|
* @param {[type]} event [description] |
|
|
|
|
|
* @return {[type]} [description] |
|
|
|
|
|
|
|
|
* @param {object} event |
|
|
*/ |
|
|
*/ |
|
|
handleOk(event) { |
|
|
|
|
|
|
|
|
handleDefault(event) |
|
|
|
|
|
{ |
|
|
event.preventDefault(); |
|
|
event.preventDefault(); |
|
|
|
|
|
|
|
|
let data = this.getData(); |
|
|
let data = this.getData(); |
|
|
|
|
|
|
|
|
this.props.cookies.forEach((cookie, index) => { |
|
|
|
|
|
if (cookie.essential === true) { |
|
|
|
|
|
data[cookie.id] = true; |
|
|
|
|
|
this.props.cookies[index].hasConsent = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.state.cookies.default.forEach((cookie, index) => { |
|
|
|
|
|
data[cookie.id] = true; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
Cookie.set(this.state.options.cookie_name, data); |
|
|
Cookie.set(this.state.options.cookie_name, data); |
|
|
this.updateEssential(); |
|
|
|
|
|
|
|
|
|
|
|
this.update(); |
|
|
this.update(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
* change to open |
|
|
|
|
|
* |
|
|
|
|
|
* @param {object} event |
|
|
* |
|
|
* |
|
|
* @param {[type]} event |
|
|
|
|
|
* @return {[type]} |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
handleClose(event) { |
|
|
|
|
|
|
|
|
handleClose(event) |
|
|
|
|
|
{ |
|
|
event.preventDefault(); |
|
|
event.preventDefault(); |
|
|
|
|
|
|
|
|
this.state.isOpen = false; |
|
|
|
|
|
|
|
|
this.root.firstChild.style.bottom = this.root.firstChild.style.bottom = -(this.root.firstChild.offsetHeight) + 'px'; |
|
|
this.update(); |
|
|
this.update(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|