|
1 | | -import { EMPTY, Observable, of, Subscriber } from 'rxjs'; |
2 | | -import { catchError, delay, take, tap } from 'rxjs/operators'; |
| 1 | +import { Observable, of, Subscriber } from 'rxjs'; |
| 2 | +import { delay, take, tap } from 'rxjs/operators'; |
3 | 3 | import { ShareButtonFuncArgs } from './share.models'; |
4 | 4 |
|
5 | 5 | /** |
@@ -50,39 +50,16 @@ export function printPage(): Observable<void> { |
50 | 50 | return new Observable((sub: Subscriber<any>) => document.defaultView.print()); |
51 | 51 | } |
52 | 52 |
|
53 | | -export function copyToClipboard({params, data, platform, updater}: ShareButtonFuncArgs<CopyToClipboardDataArgs>): Observable<void> { |
| 53 | +export function copyToClipboard({params, data, clipboard, updater}: ShareButtonFuncArgs<CopyToClipboardDataArgs>): Observable<void> { |
54 | 54 | return of(null).pipe( |
55 | 55 | tap(() => { |
56 | | - const textArea: HTMLTextAreaElement = document.createElement('textarea') as HTMLTextAreaElement; |
57 | | - |
58 | | - textArea.value = decodeURIComponent(params.url); |
59 | | - document.body.appendChild(textArea); |
60 | | - |
61 | | - // highlight TextArea to copy the sharing link |
62 | | - if (platform.IOS) { |
63 | | - const range = document.createRange(); |
64 | | - range.selectNodeContents(textArea); |
65 | | - const selection = document.defaultView.getSelection(); |
66 | | - selection.removeAllRanges(); |
67 | | - selection.addRange(range); |
68 | | - textArea.readOnly = true; |
69 | | - textArea.setSelectionRange(0, 999999); |
70 | | - } else { |
71 | | - textArea.select(); |
72 | | - } |
73 | | - document.execCommand('copy'); |
74 | | - document.body.removeChild(textArea); |
75 | | - |
| 56 | + clipboard.copy(params.url); |
76 | 57 | // Disable copy button |
77 | 58 | updater.next({icon: data.successIcon, text: data.successText, disabled: true}); |
78 | 59 | }), |
79 | 60 | delay(data.delay), |
80 | 61 | tap(() => updater.next({icon: data.icon, text: data.text, disabled: false})), |
81 | | - take(1), |
82 | | - catchError(err => { |
83 | | - console.warn('Copy link failed!', err.message); |
84 | | - return EMPTY; |
85 | | - }) |
| 62 | + take(1) |
86 | 63 | ); |
87 | 64 | } |
88 | 65 |
|
|
0 commit comments