|
|
@ -14,7 +14,7 @@ export class ClipboardDirective {
|
|
|
|
public onClick(event: MouseEvent): void {
|
|
|
|
public onClick(event: MouseEvent): void {
|
|
|
|
event.preventDefault();
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
if (!this.payload) return;
|
|
|
|
if (!this.payload) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
if (navigator.clipboard) {
|
|
|
|
if (navigator.clipboard) {
|
|
|
|
this.copyUsingClipboardAPI();
|
|
|
|
this.copyUsingClipboardAPI();
|
|
|
@ -30,6 +30,9 @@ export class ClipboardDirective {
|
|
|
|
input.select();
|
|
|
|
input.select();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
// Allowing deprecated command for older browsers where navigator is not available.
|
|
|
|
|
|
|
|
// For newer browsers where execCommand is deprecated, navigator should be available and this fallback will not be called.
|
|
|
|
|
|
|
|
// eslint-disable-next-line deprecation/deprecation
|
|
|
|
const result = document.execCommand('copy');
|
|
|
|
const result = document.execCommand('copy');
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
this.copied.emit(this.payload.toString());
|
|
|
|
this.copied.emit(this.payload.toString());
|
|
|
@ -42,8 +45,11 @@ export class ClipboardDirective {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private copyUsingClipboardAPI(): void {
|
|
|
|
private copyUsingClipboardAPI(): void {
|
|
|
|
navigator.clipboard.writeText(this.payload.toString())
|
|
|
|
navigator.clipboard.writeText(this.payload.toString()).then(() => {
|
|
|
|
.then(() => this.copied.emit(this.payload.toString()))
|
|
|
|
this.copied.emit(this.payload.toString());
|
|
|
|
.catch((error) => this.copied.emit('Error could not copy text: ' + JSON.stringify(error)));
|
|
|
|
}).catch((err) => {
|
|
|
|
|
|
|
|
this.copied.emit('Error could not copy text: ' + JSON.stringify(err));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|