-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathclipboard.ts
More file actions
39 lines (32 loc) · 1.04 KB
/
clipboard.ts
File metadata and controls
39 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as Stacks from '../../../../lib/ts/stacks';
Stacks.application.register("clipboard", class extends Stacks.StacksController {
static targets = ["source"];
sourceTarget!: HTMLElement;
connect() {
super.connect();
};
copy() {
const text = this.sourceTarget.innerText;
navigator.clipboard.writeText(text);
this.handleVisible();
}
private handleVisible() {
const { scope } = this.targets;
const hideElements = scope.findAllElements('[data-hide-on-copy]');
const showElements = scope.findAllElements('[data-show-on-copy]');
hideElements.forEach(el => {
el.classList.add("d-none");
});
showElements.forEach(el => {
el.classList.remove("d-none");
});
setTimeout(function () {
hideElements.forEach(el => {
el.classList.remove("d-none");
});
showElements.forEach(el => {
el.classList.add("d-none");
});
}, 3000);
}
});