// Копирование содержимого в буфер обмена function copyToClipboard(el, text) { if (navigator.clipboard && window.isSecureContext) { navigator.clipboard.writeText(text).then(() => { showBubble(el); }).catch(err => { console.error('Не удалось скопировать: ', err); }); } else { // Фоллбэк для копирования через execCommand const textArea = document.createElement("textarea"); textArea.value = text; // Убеждаемся, что элемент невидим и не может быть фокусирован textArea.style.position = "fixed"; textArea.style.left = "-999999px"; textArea.style.top = "0"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { const successful = document.execCommand('copy'); if (successful) { showBubble(el); // Показать уведомление "Скопировано" } else { console.error('Не удалось скопировать с помощью execCommand.'); } } catch (err) { console.error('Ошибка при копировании: ', err); } // Удаляем временное текстовое поле document.body.removeChild(textArea); } } // Отображение пузырька с текстом function showBubble(el) { // Создаем новый элемент "Скопировано" const bubble = document.createElement('span'); bubble.className = 'badge text-bg-success bubble-copy'; bubble.innerHTML = ' Скопировано!'; // Вставляем пузырь в начало элемента el.style.position = 'relative'; el.appendChild(bubble, el.firstChild); // Через некоторое время анимируем пузырик setTimeout(() => { bubble.classList.add('hide'); }, 300); // Через некоторое время удаляем пузырик setTimeout(() => { bubble.remove(); }, 1000) }