1import { Controller } from "@hotwired/stimulus" 2 3// Copia um link para a area de transferencia e pisca a confirmacao no proprio botao. 4// 5// O `prompt` continua como saida de emergencia: fora de contexto seguro a API de area de 6// transferencia nao existe, e sem ele o botao nao faria nada. Mostrar o link para copiar a 7// mao e pior que copiar sozinho, mas melhor que silencio. 8const PISCA_POR = 1500 9 10export default class extends Controller { 11 static values = { url: String, aviso: { type: String, default: "Copie o link:" } } 12 13 async copiar() { 14 if (!navigator.clipboard || !window.isSecureContext) return this.#pedirAMao() 15 16 try { 17 await navigator.clipboard.writeText(this.urlValue) 18 this.#piscar() 19 } catch { 20 this.#pedirAMao() 21 } 22 } 23 24 disconnect() { 25 clearTimeout(this.relogio) 26 } 27 28 #piscar() { 29 this.element.classList.add("copied") 30 this.relogio = setTimeout(() => this.element.classList.remove("copied"), PISCA_POR) 31 } 32 33 #pedirAMao() { 34 window.prompt(this.avisoValue, this.urlValue) 35 } 36}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.