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

Adds visually hidden announcements for alerts #566

Open
wants to merge 2 commits into
base: 1.x
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions js/wysiwyg-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file JS file for the WYSIWYG styles components.
*/

(function wysiwygStylesScript(Drupal) {
Drupal.behaviors.wysiwygStyles = {
attach: function (context) {
const wysiwygAlerts = once("allAlerts", ".alert", context);

function alertMessage(alert, type) {
const element = document.createElement("span");
element.classList.add("visually-hidden");
element.innerHTML = Drupal.t(
`Alert: "${type}"`
);
// Insert the message at the beginning of the alert.
alert.insertBefore(element, alert.firstChild);
}

wysiwygAlerts.forEach((alert) => {
if (alert.classList.contains("alert-info")) {
alertMessage(alert, "information");
} else if (alert.classList.contains("alert-danger")) {
alertMessage(alert, "danger");
} else if (alert.classList.contains("alert-failure")) {
alertMessage(alert, "failure");
} else if (alert.classList.contains("alert-success")) {
alertMessage(alert, "success");
} else {
alertMessage(alert, "default");
}
});
},
};
})(Drupal);
5 changes: 5 additions & 0 deletions localgov_base.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ wysiwyg-styles:
css:
theme:
css/components/wysiwyg-styles.css: {}
js:
js/wysiwyg-styles.js: {}
dependencies:
- core/drupal
- core/once

header:
css:
Expand Down