<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

type PopupType = 'danger' | 'info' | 'warning';
const persistentPopups: PopupType[] = ['danger', 'warning'];

export function popup(message: string, type: PopupType = 'info') {
  const $popup = $('#popup-container');
  const $alert = $('.popup-clone').clone();

  const closeAlert = () => $alert.trigger('click');

  // handle types of alerts by changing the colour
  $alert
    .addClass(`alert-${type} popup-active`)
    .removeClass('popup-clone');

  $alert.find('.popup-text').html(message);

  // warning/danger messages stay forever until clicked
  if (persistentPopups.includes(type)) {
    $('#overlay')
      .off('click.close-alert')
      .one('click.close-alert', closeAlert)
      .fadeIn();
  } else {
    setTimeout(closeAlert, 5000);
  }

  const activeElement = document.activeElement;
  if (activeElement instanceof HTMLElement) {
    activeElement.blur();
  }

  $alert.appendTo($popup).fadeIn();
}<commit_msg>use existing helper<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import { htmlElementOrNull } from './html';

type PopupType = 'danger' | 'info' | 'warning';
const persistentPopups: PopupType[] = ['danger', 'warning'];

export function popup(message: string, type: PopupType = 'info') {
  const $popup = $('#popup-container');
  const $alert = $('.popup-clone').clone();

  const closeAlert = () => $alert.trigger('click');

  // handle types of alerts by changing the colour
  $alert
    .addClass(`alert-${type} popup-active`)
    .removeClass('popup-clone');

  $alert.find('.popup-text').html(message);

  // warning/danger messages stay forever until clicked
  if (persistentPopups.includes(type)) {
    $('#overlay')
      .off('click.close-alert')
      .one('click.close-alert', closeAlert)
      .fadeIn();
  } else {
    setTimeout(closeAlert, 5000);
  }

  htmlElementOrNull(document.activeElement)?.blur();

  $alert.appendTo($popup).fadeIn();
}
{'fraction_non_alphanumeric': 0.16199095022624435, 'fraction_numerical': 0.005429864253393665, 'mean_word_length': 3.9573991031390134, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4607999', 'n_tokens_mistral': 694, 'n_tokens_neox': 657, 'n_words': 183}