File manager - Edit - /var/www/html/portal/public/pmar/js/repositorio.js
Back
/** * Função para copiar URL do arquivo para a área de transferência * @param {string} url - URL completa do arquivo * @param {HTMLElement} element - Elemento que disparou a ação (para feedback visual) */ function copyRepositorioUrl(url, element) { // Garante que a URL está completa const fullUrl = url.startsWith('http') ? url : window.location.origin + (url.startsWith('/') ? url : '/' + url); const isSecureContext = window.isSecureContext || window.location.protocol === 'https:' || window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'; // Tenta usar a API moderna do Clipboard if (isSecureContext && navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(fullUrl) .then(() => { showCopyFeedback(element, 'URL copiada com sucesso!', false); }) .catch((err) => { console.error('Erro ao copiar via Clipboard API:', err); fallbackCopyToClipboard(fullUrl, element); }); } else { // Fallback para HTTP ou navegadores antigos fallbackCopyToClipboard(fullUrl, element); } } /** * Método fallback para copiar texto usando execCommand * @param {string} text - Texto a ser copiado * @param {HTMLElement} element - Elemento para feedback visual */ function fallbackCopyToClipboard(text, element) { try { const textArea = document.createElement("textarea"); textArea.value = text; textArea.style.position = "fixed"; textArea.style.top = "-9999px"; textArea.style.left = "-9999px"; textArea.style.opacity = "0"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); textArea.setSelectionRange(0, 99999); const successful = document.execCommand("copy"); document.body.removeChild(textArea); if (successful) { showCopyFeedback(element, 'URL copiada com sucesso!', false); } else { showCopyFeedback(element, 'Erro ao copiar URL. Tente novamente.', true); } } catch (err) { console.error('Erro ao copiar:', err); showCopyFeedback(element, 'Erro ao copiar URL. Tente novamente.', true); } } /** * Mostra feedback visual ao copiar URL * @param {HTMLElement} element - Elemento que disparou a ação * @param {string} message - Mensagem a ser exibida * @param {boolean} isError - Se é erro ou sucesso */ function showCopyFeedback(element, message, isError) { // Feedback no próprio elemento (tooltip) const originalTitle = element.getAttribute('title'); const icon = element.querySelector('i'); const originalClass = icon.className; // Muda o ícone temporariamente if (!isError) { icon.className = 'fa-solid fa-check text-success'; element.setAttribute('title', message); } else { icon.className = 'fa-solid fa-exclamation-triangle text-danger'; element.setAttribute('title', message); } // Restaura após 2 segundos setTimeout(() => { icon.className = originalClass; element.setAttribute('title', originalTitle || 'Copiar URL'); }, 2000); // Feedback global (toast) const existingFeedback = document.getElementById('repositorio-copy-feedback'); if (existingFeedback) { existingFeedback.remove(); } const feedback = document.createElement('div'); feedback.id = 'repositorio-copy-feedback'; feedback.className = `alert ${isError ? 'alert-danger' : 'alert-success'} position-fixed`; feedback.style.cssText = 'top: 20px; right: 20px; z-index: 9999; min-width: 250px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); animation: slideInRight 0.3s ease-out;'; feedback.innerHTML = ` <i class="fas ${isError ? 'fa-exclamation-circle' : 'fa-check-circle'} me-2"></i> ${message} `; // Adiciona animação CSS se não existir if (!document.getElementById('repositorio-copy-style')) { const style = document.createElement('style'); style.id = 'repositorio-copy-style'; style.textContent = ` @keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } } `; document.head.appendChild(style); } document.body.appendChild(feedback); // Remove após 3 segundos setTimeout(() => { feedback.style.transition = 'opacity 0.3s ease-out, transform 0.3s ease-out'; feedback.style.opacity = '0'; feedback.style.transform = 'translateX(100%)'; setTimeout(() => { if (feedback.parentNode) { feedback.remove(); } }, 300); }, 3000); }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings