Skip to content

Commit

Permalink
feat: Remember given consent for session
Browse files Browse the repository at this point in the history
Implements #92
  • Loading branch information
octfx committed Apr 15, 2024
1 parent 92909d2 commit 40f5a00
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion resources/modules/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ const makeIframe = function(ev) {
const togglePrivacyClickListener = function (event) {
event.stopPropagation();

if (window.sessionStorage.getItem(getSessionStorageKey()) === '1') {
makeIframe(event);
return;
}

if (event.target.classList.contains('embedvideo-loader__link')) {
return;
}
Expand All @@ -161,6 +166,10 @@ const makeIframe = function(ev) {
privacyNotice.classList.toggle('hidden');
};

const getSessionStorageKey = function () {
return `ev-${ev.dataset.service}-consent-given`;
}

/** @type HTMLDivElement|null */
const consentDiv = wrapper.querySelector('.embedvideo-consent');
let iframeConfig = ev.dataset.iframeconfig;
Expand All @@ -179,7 +188,10 @@ const makeIframe = function(ev) {
const dismissBtn = consentDiv.querySelector('.embedvideo-privacyNotice__dismiss');

consentDiv.addEventListener('click', togglePrivacyClickListener);
continueBtn.addEventListener('click', makeIframe);
continueBtn.addEventListener('click', (event) => {
window.sessionStorage.setItem(getSessionStorageKey(), '1');
makeIframe(event);
});
dismissBtn.addEventListener('click', togglePrivacyClickListener);
} else {
consentDiv.addEventListener('click', makeIframe);
Expand Down

0 comments on commit 40f5a00

Please sign in to comment.