1import { Controller } from "../stimulus.js"; 2 3window.ShareDialog = { 4 controller: null, 5 openDialog: function () { 6 if (this.controller) { 7 this.controller.open(); 8 } else { 9 console.error("Share dialog controller is not initialized"); 10 } 11 } 12}; 13 14export default class extends Controller { 15 static targets = ["modal", "copyFeedback"] 16 static values = { url: String } 17 18 #copyTimeout = null; 19 20 #clearFeedback() { 21 clearTimeout(this.#copyTimeout); 22 this.#copyTimeout = null; 23 if (this.hasCopyFeedbackTarget) { 24 this.copyFeedbackTarget.textContent = ""; 25 } 26 } 27 28 connect() { 29 window.ShareDialog.controller = this; 30 this.eventListener = this.enableBodyScroll.bind(this) 31 this.modalTarget.addEventListener("close", this.eventListener) 32 } 33 34 disconnect() { 35 if (window.ShareDialog.controller) { 36 window.ShareDialog.controller = null; 37 } 38 this.modalTarget.removeEventListener("close", this.eventListener) 39 this.#clearFeedback(); 40 } 41 42 open() { 43 this.modalTarget.showModal() 44 } 45 46 close() { 47 this.modalTarget.close() 48 } 49 50 enableBodyScroll() { 51 document.body.classList.remove('overflow-hidden') 52 } 53 54 clickOutside(event) { 55 if (event.target === this.modalTarget) { 56 this.close() 57 } 58 } 59 60 async copy(event) { 61 event.preventDefault(); 62 const show = (msg) => { 63 this.#clearFeedback(); 64 this.copyFeedbackTarget.textContent = msg; 65 this.#copyTimeout = setTimeout(() => this.#clearFeedback(), 2000); 66 }; 67 if (navigator.clipboard) { 68 try { 69 await navigator.clipboard.writeText(this.urlValue); 70 show("Copied!"); 71 } catch { 72 show("Could not copy"); 73 } 74 } else { 75 const el = document.createElement("textarea"); 76 el.value = this.urlValue; 77 el.style.cssText = "position:fixed;opacity:0"; 78 document.body.appendChild(el); 79 el.select(); 80 document.execCommand("copy"); 81 document.body.removeChild(el); 82 show("Copied!"); 83 } 84 } 85 86 print(event) { 87 event.preventDefault(); 88 this.close(); 89 window.print(); 90 } 91}
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.