fix: Kopieren-Funktion im Dashboard repariert
Änderungen: - Verbesserte copyEmbedCode() Funktion mit robusterem Clipboard-Handling - Fallback für ältere Browser hinzugefügt - Besseres Error-Handling und Logging - Erfolgs-Benachrichtigungen optimiert Die Kopieren-Funktion funktioniert jetzt zuverlässig in allen Browsern.
This commit is contained in:
@@ -594,12 +594,58 @@ function getSessionId() {
|
||||
// ============================================
|
||||
function copyEmbedCode() {
|
||||
const embedCode = document.getElementById('embedCode');
|
||||
if (!embedCode) return;
|
||||
if (!embedCode) {
|
||||
console.error('embedCode element not found');
|
||||
return;
|
||||
}
|
||||
|
||||
const text = embedCode.textContent;
|
||||
copyToClipboard('embedCode');
|
||||
// Get the text content and clean it up
|
||||
let text = embedCode.textContent || embedCode.innerText;
|
||||
text = text.trim();
|
||||
|
||||
// Show success message
|
||||
// Try modern clipboard API first
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
showNotification('Code in Zwischenablage kopiert!', 'success');
|
||||
showCopySuccess();
|
||||
}).catch(err => {
|
||||
console.error('Clipboard API failed:', err);
|
||||
fallbackCopy(text);
|
||||
});
|
||||
} else {
|
||||
// Fallback for older browsers
|
||||
fallbackCopy(text);
|
||||
}
|
||||
}
|
||||
|
||||
function fallbackCopy(text) {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
textarea.style.position = 'fixed';
|
||||
textarea.style.top = '0';
|
||||
textarea.style.left = '0';
|
||||
textarea.style.opacity = '0';
|
||||
document.body.appendChild(textarea);
|
||||
textarea.focus();
|
||||
textarea.select();
|
||||
|
||||
try {
|
||||
const successful = document.execCommand('copy');
|
||||
if (successful) {
|
||||
showNotification('Code in Zwischenablage kopiert!', 'success');
|
||||
showCopySuccess();
|
||||
} else {
|
||||
showNotification('Kopieren fehlgeschlagen. Bitte manuell kopieren.', 'error');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Fallback copy failed:', err);
|
||||
showNotification('Kopieren fehlgeschlagen. Bitte manuell kopieren.', 'error');
|
||||
}
|
||||
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
|
||||
function showCopySuccess() {
|
||||
const copySuccess = document.getElementById('copySuccess');
|
||||
if (copySuccess) {
|
||||
copySuccess.style.display = 'flex';
|
||||
@@ -611,23 +657,24 @@ function copyEmbedCode() {
|
||||
|
||||
function copyToClipboard(elementId) {
|
||||
const element = document.getElementById(elementId);
|
||||
if (!element) return;
|
||||
if (!element) {
|
||||
console.error('Element not found:', elementId);
|
||||
return;
|
||||
}
|
||||
|
||||
const text = element.textContent;
|
||||
let text = element.textContent || element.innerText;
|
||||
text = text.trim();
|
||||
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
showNotification('In Zwischenablage kopiert', 'success');
|
||||
}).catch(err => {
|
||||
console.error('Copy failed:', err);
|
||||
// Fallback
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(textarea);
|
||||
showNotification('In Zwischenablage kopiert', 'success');
|
||||
});
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
showNotification('In Zwischenablage kopiert!', 'success');
|
||||
}).catch(err => {
|
||||
console.error('Copy failed:', err);
|
||||
fallbackCopy(text);
|
||||
});
|
||||
} else {
|
||||
fallbackCopy(text);
|
||||
}
|
||||
}
|
||||
|
||||
// Make functions available globally
|
||||
|
||||
Reference in New Issue
Block a user