Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A11y fixes #1158

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions tarteaucitron.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ var tarteaucitron = {
html = '',
index,
orientation = 'Top',
modalAttrs = '',
cat = ['ads', 'analytic', 'api', 'comment', 'social', 'support', 'video', 'other'],
i;

Expand Down Expand Up @@ -419,10 +420,14 @@ var tarteaucitron = {
orientation = 'Bottom';
}

if (tarteaucitron.parameters.orientation === 'middle' || tarteaucitron.parameters.orientation === 'popup') {
modalAttrs = ' role="dialog" aria-modal="true" aria-labelledby="tac_title"';
}

if (tarteaucitron.parameters.highPrivacy && !tarteaucitron.parameters.AcceptAllCta) {
html += '<div tabindex="-1" id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
html += '<div tabindex="-1" id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '"' + modalAttrs + '>';
//html += '<div class="tarteaucitronAlertBigWrapper">';
html += ' <span id="tarteaucitronDisclaimerAlert">';
html += ' <span id="tarteaucitronDisclaimerAlert" role="paragraph">';
html += ' ' + tarteaucitron.lang.alertBigPrivacy;
html += ' </span>';
//html += ' <span class="tarteaucitronAlertBigBtnWrapper">';
Expand All @@ -440,9 +445,9 @@ var tarteaucitron = {
//html += '</div>';
html += '</div>';
} else {
html += '<div tabindex="-1" id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
html += '<div tabindex="-1" id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '"' + modalAttrs + '>';
//html += '<div class="tarteaucitronAlertBigWrapper">';
html += ' <span id="tarteaucitronDisclaimerAlert">';
html += ' <span id="tarteaucitronDisclaimerAlert" role="paragraph">';

if (tarteaucitron.parameters.highPrivacy) {
html += ' ' + tarteaucitron.lang.alertBigPrivacy;
Expand Down Expand Up @@ -778,6 +783,15 @@ var tarteaucitron = {
});
}

// accessibility: on click on "Allow" in the site (not in TAC module), move focus to the loaded service's parent
var allowBtnsInSite = document.querySelectorAll(".tarteaucitronAllow:not(#tarteaucitronRoot .tarteaucitronAllow)");
for (i = 0; i < allowBtnsInSite.length; i++) {
tarteaucitron.addClickEventToElement(allowBtnsInSite[i], function () {
this.closest('.tac_activate').parentNode.setAttribute("tabindex","-1");
this.closest('.tac_activate').parentNode.focus();
});
}

var allowBtns = document.getElementsByClassName("tarteaucitronAllow");
for (i = 0; i < allowBtns.length; i++) {
tarteaucitron.addClickEventToElement(allowBtns[i], function () {
Expand Down Expand Up @@ -985,6 +999,10 @@ var tarteaucitron = {
if (property == "display" && value == "block" && id == "tarteaucitronBack") {
document.getElementById(id).style["opacity"] = "0.7";
}

if (property == "display" && value == "block" && id == "tarteaucitronAlertBig" && (tarteaucitron.parameters.orientation == "middle"|| tarteaucitron.parameters.orientation == "popup")) {
tarteaucitron.userInterface.focusTrap('tarteaucitronAlertBig');
}
}
}
},
Expand Down Expand Up @@ -1258,7 +1276,7 @@ var tarteaucitron = {
if (document.getElementsByTagName('body')[0].classList !== undefined) {
document.getElementsByTagName('body')[0].classList.add('tarteaucitron-modal-open');
}
tarteaucitron.userInterface.focusTrap();
tarteaucitron.userInterface.focusTrap('tarteaucitron');
tarteaucitron.userInterface.jsSizing('main');

//ie compatibility
Expand Down Expand Up @@ -1327,15 +1345,15 @@ var tarteaucitron = {

if (typeof(window.dispatchEvent) === 'function') {window.dispatchEvent(tacClosePanelEvent);}
},
"focusTrap": function() {
"focusTrap": function(parentElement) {
"use strict";

var focusableEls,
firstFocusableEl,
lastFocusableEl,
filtered;

focusableEls = document.getElementById('tarteaucitron').querySelectorAll('a[href], button');
focusableEls = document.getElementById(parentElement).querySelectorAll('a[href], button');
filtered = [];

// get only visible items
Expand All @@ -1349,7 +1367,7 @@ var tarteaucitron = {
lastFocusableEl = filtered[filtered.length - 1];

//loop focus inside tarteaucitron
document.getElementById('tarteaucitron').addEventListener("keydown", function (evt) {
document.getElementById(parentElement).addEventListener("keydown", function (evt) {

if ( evt.key === 'Tab' || evt.keyCode === 9 ) {

Expand Down
Loading