migrate alert-box in lib, up route airwatch demo layout
This commit is contained in:
parent
fe63fec58f
commit
d0b5ad10f6
15 changed files with 174 additions and 9 deletions
54
my-workspace/projects/sae-lib/buttons/copy/copy.ts
Normal file
54
my-workspace/projects/sae-lib/buttons/copy/copy.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
import {Component, Input} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-copy',
|
||||
imports: [],
|
||||
templateUrl: './copy.html',
|
||||
styleUrl: './copy.scss'
|
||||
})
|
||||
export class Copy {
|
||||
|
||||
@Input() textToCopy = "";
|
||||
|
||||
copy() {
|
||||
this.copyTextToClipboard(this.textToCopy)
|
||||
}
|
||||
|
||||
fallbackCopyTextToClipboard(text: any) {
|
||||
var textArea = document.createElement("textarea");
|
||||
textArea.value = text;
|
||||
|
||||
// Avoid scrolling to bottom
|
||||
textArea.style.top = "0";
|
||||
textArea.style.left = "0";
|
||||
textArea.style.position = "fixed";
|
||||
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
|
||||
try {
|
||||
var successful = document.execCommand('copy');
|
||||
var msg = successful ? 'successful' : 'unsuccessful';
|
||||
console.log('Fallback: Copying text command was ' + msg);
|
||||
} catch (err) {
|
||||
console.error('Fallback: Oops, unable to copy', err);
|
||||
}
|
||||
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
|
||||
copyTextToClipboard(text: string) {
|
||||
console.log("copier", text)
|
||||
if (!navigator.clipboard) {
|
||||
this.fallbackCopyTextToClipboard(text);
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(text).then(function () {
|
||||
console.log('Async: Copying to clipboard was successful!');
|
||||
}, function (err) {
|
||||
console.error('Async: Could not copy text: ', err);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue