-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #853 from City-of-Helsinki/UHF-10570
UHF-10570: Aria label and role for the IBM chats with JavaScript
- Loading branch information
Showing
4 changed files
with
50 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(function (Drupal) { | ||
'use strict'; | ||
|
||
Drupal.behaviors.chat_enhancer = { | ||
attach: function (context, settings) { | ||
// Add the chat_user_consent functionality | ||
window.chat_user_consent = { | ||
retrieveUserConsent: () => (Drupal.cookieConsent.getConsentStatus(['chat'])), | ||
confirmUserConsent: () => { | ||
if (Drupal.cookieConsent.getConsentStatus(['chat'])) return; | ||
Drupal.cookieConsent.setAcceptedCategories(['chat']); | ||
} | ||
}; | ||
|
||
// Chat accessibility enhancements | ||
let attemptCount = 0; | ||
const maxAttempts = 10; // Maximum number of attempts | ||
|
||
// Function to check for the element and set attributes | ||
function checkAndSetAttributes() { | ||
const element = document.getElementById('aca-wbc-chat-app-button'); | ||
|
||
if (element) { | ||
// Check and set the 'role' attribute if not set | ||
if (!element.hasAttribute('role')) { | ||
element.setAttribute('role', 'region'); | ||
} | ||
|
||
// Check and set the 'aria-labelledby' attribute if not set | ||
if (!element.hasAttribute('aria-labelledby')) { | ||
element.setAttribute('aria-labelledby', 'chat-app-button'); | ||
} | ||
} else if (attemptCount < maxAttempts) { | ||
// If element is not found, wait and try again after a delay | ||
attemptCount++; | ||
setTimeout(checkAndSetAttributes, 1000); | ||
} | ||
} | ||
|
||
// Start the initial check | ||
checkAndSetAttributes(); | ||
} | ||
|
||
} | ||
|
||
})(Drupal); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters