1import { Controller } from "@hotwired/stimulus" 2 3export default class extends Controller { 4 static values = { url: String, title: String } 5 static targets = ["copyLabel", "copyIcon", "copyButton", "popover"] 6 7 connect() { 8 this.outsideClickHandler = (e) => { 9 if (!this.element.contains(e.target)) this.closePopover() 10 } 11 } 12 13 disconnect() { 14 document.removeEventListener("click", this.outsideClickHandler) 15 } 16 17 togglePopover(event) { 18 event.stopPropagation() 19 const isHidden = this.popoverTarget.classList.contains("hidden") 20 if (isHidden) { 21 this.popoverTarget.classList.remove("hidden") 22 setTimeout(() => document.addEventListener("click", this.outsideClickHandler), 0) 23 } else { 24 this.closePopover() 25 } 26 } 27 28 closePopover() { 29 this.popoverTarget.classList.add("hidden") 30 document.removeEventListener("click", this.outsideClickHandler) 31 } 32 33 async copy(event) { 34 event.preventDefault() 35 try { 36 await navigator.clipboard.writeText(this.urlValue) 37 } catch (_) { 38 const ta = document.createElement("textarea") 39 ta.value = this.urlValue 40 document.body.appendChild(ta) 41 ta.select() 42 document.execCommand("copy") 43 document.body.removeChild(ta) 44 } 45 this.flashCopied() 46 } 47 48 flashCopied() { 49 const label = this.copyLabelTarget 50 const icon = this.copyIconTarget 51 const btn = this.copyButtonTarget 52 const originalLabel = label.textContent 53 const originalIcon = icon.textContent 54 label.textContent = "Copied!" 55 icon.textContent = "check" 56 btn.classList.add("ring-2", "ring-success-300", "bg-success-50", "text-success-700") 57 setTimeout(() => { 58 label.textContent = originalLabel 59 icon.textContent = originalIcon 60 btn.classList.remove("ring-2", "ring-success-300", "bg-success-50", "text-success-700") 61 }, 1800) 62 } 63}
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.