Skip to content

Commit

Permalink
Merge branch '1.x' into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
zoglo committed Dec 13, 2024
2 parents ee85bdf + 5517aa9 commit 9181089
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
- '%contao_cookiebar.consent_log%'
- '%contao_cookiebar.storage_key%'
- '%contao_cookiebar.consider_dnt%'
- '%contao_cookiebar.disable_focustrap%'
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
- { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }
Expand Down
3 changes: 2 additions & 1 deletion docs/BASICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ contao_cookiebar:
consider_dnt: false
anonymize_ip: false
consent_log: false
disable_focustrap: false
lifetime: 63072000
storage_key: ccb_contao_token
iframe_types:
Expand All @@ -39,7 +40,7 @@ Parameter | Description
`consider_dnt` | Consider "Do not Track" browser setting
`consent_log` | Enables/disables consent logging. With each action by the visitor, information about the made choice of cookies is stored.
`anonymize_ip` | Anonymizes the visitor's IP address for each log entry using [Symfony IP Address Anonymizer](https://symfony.com/blog/new-in-symfony-4-4-ip-address-anonymizer).
`consent_log` | Defines whether the Consent Log is enabled or disabled.
`disable_focustrap` | Can be used to disable the focus trap that was introduced in `1.17`.
`lifetime` | Time in seconds that specifies how long the cookie bar settings apply. If the time has expired, the cookie bar is displayed again. If 0 is passed, the cookie bar will never be displayed again automatically and can only be triggered via the version within the cookie bar configuration. (Default: `63072000` = 2 years)
`storage_key` | The key used for localStorage
`iframe_types.*` | An array of iFrame-Types and the corresponding templates. By customizing this array, any type can be added (see [Create own iFrame-Types](EXTEND_IFRAME.md))
Expand Down
26 changes: 20 additions & 6 deletions public/scripts/cookiebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let ContaoCookiebar = (function () {
pageId: null,
hideOnInit: false,
blocking: false,
focusTrap: true,
version: null,
lifetime: 63072000,
consentLog: false,
Expand Down Expand Up @@ -77,8 +78,11 @@ let ContaoCookiebar = (function () {
// Register trigger events
registerTriggerEvents();

// Initialize focus trap
initFocusTrap();

if (cookiebar.settings.focusTrap) {
// Initialize focus trap
initFocusTrap();
}

if (cookiebar.settings.blocking) {
// Register inert observer
Expand Down Expand Up @@ -661,6 +665,11 @@ let ContaoCookiebar = (function () {
if (!(e.key === 'Tab' || e.keyCode === 9))
return;

if (!cookiebar.focused) {
cookiebar.focused = true;
cookiebar.firstFocus?.classList.remove('cc-hide-focus')
}

if (document.activeElement === cookiebar.lastFocus && !e.shiftKey) {
e.preventDefault();
cookiebar.firstFocus?.focus()
Expand All @@ -684,13 +693,18 @@ let ContaoCookiebar = (function () {
})
}

// Focus the first element when opening the cookiebar
cookiebar.firstFocus.focus()
if (!cookiebar.settings.focusTrap)
return;

if (state)
if (state) {
document.addEventListener('keydown', focusTrap);
else
cookiebar.dom.querySelector('.cc-inner').onanimationend = () => {
cookiebar.firstFocus?.classList.add('cc-hide-focus')
cookiebar.firstFocus?.focus()
}
} else {
document.removeEventListener('keydown', focusTrap)
}
}

// Check for children that are added whilst the page builds (race-condition)
Expand Down
2 changes: 1 addition & 1 deletion public/scripts/cookiebar.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/styles/_cookiebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
}
}

.cc-focus {
.cc-focus:not(.cc-hide-focus) {

&:focus-visible {
outline: 3px dashed var(--ccb-focus-clr);
Expand Down
2 changes: 1 addition & 1 deletion public/styles/cookiebar_default.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/styles/cookiebar_simple.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function getConfigTreeBuilder(): TreeBuilder
->prototype('scalar')->end()
->end()
->end()
->booleanNode('disable_focustrap')
->defaultFalse()
->end()
->end()
;

Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/ContaoCookiebarExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('contao_cookiebar.storage_key', $config['storage_key']);
$container->setParameter('contao_cookiebar.iframe_types', $config['iframe_types']);
$container->setParameter('contao_cookiebar.page_templates', $config['page_templates']);
$container->setParameter('contao_cookiebar.disable_focustrap', $config['disable_focustrap']);
}
}
Loading

0 comments on commit 9181089

Please sign in to comment.