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

UHF-10570: Aria label and role for the IBM chats with JavaScript #853

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
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
46 changes: 46 additions & 0 deletions assets/js/chat_enhancer.js
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);
12 changes: 0 additions & 12 deletions assets/js/user_consent_functions.js

This file was deleted.

6 changes: 3 additions & 3 deletions helfi_platform_config.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ chat_leijuke:
- core/drupal
- core/drupalSettings

user_consent_functions:
version: 1.0.x
chat_enhancer:
version: 1.0.0
header: true
js:
assets/js/user_consent_functions.js: {}
assets/js/chat_enhancer.js: {}
dependencies:
- core/drupal

Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Block/IbmChatApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function blockSubmit($form, FormStateInterface $formState) {
*/
public function build() {

$library = ['helfi_platform_config/user_consent_functions'];
$library = ['helfi_platform_config/chat_enhancer'];

$build = [];

Expand Down