| 14 | private clip: ClipboardJS; |
| 15 | |
| 16 | public constructor(btn: CopyBtn, options: ClipboardOptions) { |
| 17 | /** |
| 18 | * btn: The button to bind the copy action to |
| 19 | * options: Either the raw text to write to clipboard, or the input field whose value should be used |
| 20 | */ |
| 21 | this.clip = new ClipboardJS(btn, { |
| 22 | text() { |
| 23 | const textToCopy = options.text |
| 24 | ? options.text |
| 25 | : DPClipboard.getFieldValue(options.fieldId); |
| 26 | return textToCopy; |
| 27 | }, |
| 28 | }); |
| 29 | this.clip.on("error", () => |
| 30 | console.error("An error occurred while copying to clipboard"), |
| 31 | ); |
| 32 | this.clip.on("success", DPClipboard.onSuccess); |
| 33 | } |
| 34 | |
| 35 | public destroy() { |
| 36 | this.clip.destroy(); |