2201bubble.className = 'tlk__bubble tlk__bubble_visible';22022203if (reason === 'success') {2204bubble.classList.add('tlk__bubble_success');2205}22062207var closeButton = document.createElement('div');2208closeButton.className = 'tlk__bubble-close';2209closeButton.textContent = '×';22102211var text = document.createElement('div');2212text.className = 'tlk__bubble-text';
text.textContent = message; bubble.appendChild(closeButton); bubble.appendChild(text); return { bubble: bubble, closeButton: closeButton, };}/** * Создает контейнер для уведомлений * @returns {HTMLElement} */function tma__createNotificationsContainer() { var div = document.createElement('div'); div.id = 'tlk_bubble-container'; div.className = 'tlk__bubble-container'; return div;}/** * Показывает уведомление * @param {string} message * @param {NotificationReason} [reason] */function tma__showNotification(message, reason) { var MAX_BUBBLES = 4; var DELAY_MS = 3000; var notificationContainer = document.getElementById('tlk_bubble-container'); if (!notificationContainer) { notificationContainer = tma__createNotificationsContainer(); document.body.appendChild(notificationContainer); } var existingBubbles = notificationContainer.querySelectorAll('.tlk__bubble.tlk__bubble_visible'); // Удаляем самый старый bubble if (existingBubbles.length >= MAX_BUBBLES) { var oldestBubble = existingBubbles[0]; tma__closeNotification(oldestBubble); } var notificationElements = tma__createNotification(message, reason); notificationElements.closeButton.addEventListener('click', function () { tma__closeNotification(notificationElements.bubble); }); notificationContainer.insertAdjacentElement('beforeend', notificationElements.bubble); // Удаление после задержки 3с var timerId = setTimeout(function () { tma__closeNotification(notificationElements.bubble); }, DELAY_MS); notificationElements.bubble.dataset.id = timerId;}/** * Закрывает всплывающее сообщение * * @param {HTMLElement} bubble - элемент bubble для закрытия */function tma__closeNotification(bubble) { // Элемент может быть закрыт вручную или по таймеру if (!bubble) { return; } var bubbleId = bubble.dataset.id; clearTimeout(parseInt(bubbleId, 10)); bubble.classList.remove('tlk__bubble_visible'); bubble.classList.add('tlk__bubble_hidden'); bubble.addEventListener( 'animationend', function () { bubble.remove(); }, { once: true } );}/**