Skip to content

Commit

Permalink
Made improvements to the blocking template (#148)
Browse files Browse the repository at this point in the history
------

Check within the blocking template if the cookiebar in the parent document is already initialized, otherwise wait with the execution of the script until the parent is loaded.
  • Loading branch information
doishub committed Feb 3, 2023
1 parent 782dbd6 commit 3970143
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Resources/contao/templates/cookiebar/ccb_element_blocker.html5
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,22 @@
}
</style>
<script>
if(parent.cookiebar.issetCookie(<?=$this->id?>)){
const decoder = document.createElement('textarea');
decoder.innerHTML = '<?=$this->redirect?>';
// Check if the cookie bar is ready, otherwise respond to document load (#148)
if(parent.cookiebar){
redirectIfNecessary()
}else{
parent.addEventListener('load', () => {
redirectIfNecessary()
})
}

function redirectIfNecessary(){
if(parent.cookiebar.issetCookie(<?=$this->id?>)){
const decoder = document.createElement('textarea');
decoder.innerHTML = '<?=$this->redirect?>';

window.location.href = decoder.value;
window.location.href = decoder.value;
}
}
</script>
<?php $this->endblock(); ?>
Expand Down

0 comments on commit 3970143

Please sign in to comment.