summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/alert_handler.js
blob: 3c867f196d69469b29524222fbcac74d184a1831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 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
// You can follow this effort in the following epic
// https://gitlab.com/groups/gitlab-org/-/epics/4070

export default function initAlertHandler() {
  const DISMISSIBLE_SELECTORS = ['.gl-alert', '.gl-banner'];
  const DISMISS_LABEL = '[aria-label="Dismiss"]';
  const DISMISS_CLASS = '.gl-alert-dismiss';

  DISMISSIBLE_SELECTORS.forEach((selector) => {
    const elements = document.querySelectorAll(selector);
    elements.forEach((element) => {
      const button = element.querySelector(DISMISS_LABEL) || element.querySelector(DISMISS_CLASS);
      if (!button) {
        return;
      }
      button.addEventListener('click', () => element.remove());
    });
  });
}