debian-mirror-gitlab/app/assets/javascripts/alert_handler.js

22 lines
824 B
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
// This allows us to dismiss alerts and banners that we've migrated from bootstrap
// Note: This ONLY works on elements that are created on page load
2020-11-24 15:15:51 +05:30
// You can follow this effort in the following epic
// https://gitlab.com/groups/gitlab-org/-/epics/4070
export default function initAlertHandler() {
2021-01-03 14:25:43 +05:30
const DISMISSIBLE_SELECTORS = ['.gl-alert', '.gl-banner'];
const DISMISS_LABEL = '[aria-label="Dismiss"]';
const DISMISS_CLASS = '.gl-alert-dismiss';
2020-11-24 15:15:51 +05:30
2021-03-08 18:12:59 +05:30
DISMISSIBLE_SELECTORS.forEach((selector) => {
2021-01-03 14:25:43 +05:30
const elements = document.querySelectorAll(selector);
2021-03-08 18:12:59 +05:30
elements.forEach((element) => {
2021-01-03 14:25:43 +05:30
const button = element.querySelector(DISMISS_LABEL) || element.querySelector(DISMISS_CLASS);
if (!button) {
return;
}
button.addEventListener('click', () => element.remove());
});
});
2020-11-24 15:15:51 +05:30
}