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 28, 2021
1 parent d64f328 commit 7ddd28b
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions site/assets/js/tac.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,11 @@
alert.querySelector('.tarteaucitronDeny').innerHTML = tarteaucitron.lang.denyAll
}, { once: true })

window.addEventListener('tac.open_panel', function () {
document.querySelectorAll('#tarteaucitronServices_api button').forEach(function (button) {
button.classList.add('btn', 'btn-sm', 'ms-2')
})
}, { once: true })

document.addEventListener(
'googletagmanager_added',
window.addEventListener('tac.open_panel',
function () {
var ask = document.querySelector(
'#googletagmanagerLine .tarteaucitronAsk'
)
var choiceEvent =
'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)

document.querySelectorAll('#tarteaucitronServices_api button').forEach(function (button) {
button.classList.add('btn', 'btn-sm', 'ms-2')
})
var allowConsentButton = document.querySelector('#tarteaucitronAllAllowed')
var denyConsentButton = document.querySelector('#tarteaucitronAllDenied')
var checkboxes = document.querySelectorAll('.form-check-input')
Expand All @@ -83,6 +64,29 @@
},
{ once: true }
)

document.addEventListener(
'googletagmanager_added',
function () {
var ask = document.querySelector(
'#googletagmanagerLine .tarteaucitronAsk'
)
var choiceEvent =
'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 +
'"' +
((document.cookie.match(/^(?:.*;)?\s*cookie-consent\s*=\s*([^;]+)(?:.*)?$/)||[,null])[1] == '!googletagmanager=true' ? "checked" : "") +
'><label class="form-check-label visually-hidden" for="googletagmanagerAllowed">Google Tag Manager</label></div>'
)
ask.innerHTML = ''
ask.append(toggle)
},
{ once: true }
)
})()

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

0 comments on commit 7ddd28b

Please sign in to comment.