Skip to content

Commit

Permalink
fix(#831): checkboxes display when user accept or deny cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
MewenLeHo committed Oct 18, 2021
1 parent 54f50d7 commit 363808f
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions site/assets/js/tac.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,44 @@
}, { once: true })

document.addEventListener(
"googletagmanager_added",
'googletagmanager_added',
function () {
var ask = document.querySelector(
'#googletagmanagerLine .tarteaucitronAsk'
);
)
var choiceEvent =
'tarteaucitron.userInterface.respond(document.getElementById("googletagmanagerAllowed"),document.getElementById("googletagmanagerAllowed").checked);';
'tarteaucitron.userInterface.respond(document.getElementById("googletagmanagerAllowed"),document.getElementById("googletagmanagerAllowed").checked);'
var toggle = document
.createRange()
.createContextualFragment(
'<div class="form-check form-switch my-2 my-lg-0"><input class="form-check-input ms-0" type="checkbox" id="googletagmanagerAllowed" aria-describedby="tacCLgoogletagmanager" onchange="' +
choiceEvent +
'"><label class="form-check-label visually-hidden" for="googletagmanagerAllowed">Google Tag Manager</label></div>'
);
ask.innerHTML = "";
ask.append(toggle);
)
ask.innerHTML = ''
ask.append(toggle)

var allowConsentButton = document.querySelector('.tarteaucitronAllow')
var denyConsentButton = document.querySelector('.tarteaucitronDeny')
var allowConsentButton = document.querySelector('#tarteaucitronAllAllowed')
var denyConsentButton = document.querySelector('#tarteaucitronAllDenied')
var checkboxes = document.querySelectorAll('.form-check-input')

[allowConsentButton].forEach(function (button) {
button.addEventListener('click', function () {
for (var i = 0; i < checkboxes.length; i++) {
if (!checkboxes.checked) {
checkboxes[i].checked = true;
}
allowConsentButton.addEventListener('click', function () {
for (var i = 0; i < checkboxes.length; i++) {
if (!checkboxes.checked) {
checkboxes[i].checked = true
}
})
});

[denyConsentButton].forEach(function (button) {
button.addEventListener('click', function () {
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes.checked !== true) {
checkboxes[i].checked = false;
}
}
})
denyConsentButton.addEventListener('click', function () {
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes.checked !== true) {
checkboxes[i].checked = false
}
});
});
}
})
},
{ once: true }
);
)
})()

if (typeof tarteaucitron !== 'undefined') {
Expand Down

0 comments on commit 363808f

Please sign in to comment.