1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-28 12:45:45 +01:00

fix copying

This commit is contained in:
Kyle Spearrin 2018-08-17 12:25:21 -04:00
parent d215e0716e
commit bcb44e8cf7
4 changed files with 15 additions and 6 deletions

2
jslib

@ -1 +1 @@
Subproject commit 1f9fbe43d7a78349e6fe994fa70d9b773af5c0f9 Subproject commit bf9a9c5f9fb5933faeeb07a85f127373ebfe7284

View File

@ -87,7 +87,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit {
} }
this.analytics.eventTrack.next({ action: 'Copied ' + aType }); this.analytics.eventTrack.next({ action: 'Copied ' + aType });
this.platformUtilsService.copyToClipboard(value, { doc: window.document }); this.platformUtilsService.copyToClipboard(value, { window: window });
this.toasterService.popAsync('info', null, this.toasterService.popAsync('info', null,
this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey))); this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey)));
} }

View File

@ -119,7 +119,7 @@ export class CiphersComponent extends BaseCiphersComponent implements OnDestroy
} }
this.analytics.eventTrack.next({ action: 'Copied ' + aType.toLowerCase() + ' from listing.' }); this.analytics.eventTrack.next({ action: 'Copied ' + aType.toLowerCase() + ' from listing.' });
this.platformUtilsService.copyToClipboard(value, { doc: window.document }); this.platformUtilsService.copyToClipboard(value, { window: window });
this.toasterService.popAsync('info', null, this.toasterService.popAsync('info', null,
this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey))); this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey)));
} }

View File

@ -208,10 +208,19 @@ export class WebPlatformUtilsService implements PlatformUtilsService {
} }
copyToClipboard(text: string, options?: any): void { copyToClipboard(text: string, options?: any): void {
const doc: Document = options ? options.doc : window.document; let win = window;
if ((window as any).clipboardData && (window as any).clipboardData.setData) { let doc = window.document;
if (options && (options.window || options.win)) {
win = options.window || options.win;
doc = win.document;
} else if (options && options.doc) {
doc = options.doc;
}
if ((win as any).navigator.clipboard && (win as any).navigator.clipboard.writeText) {
(win as any).navigator.clipboard.writeText(text);
} else if ((win as any).clipboardData && (win as any).clipboardData.setData) {
// IE specific code path to prevent textarea being shown while dialog is visible. // IE specific code path to prevent textarea being shown while dialog is visible.
(window as any).clipboardData.setData('Text', text); (win as any).clipboardData.setData('Text', text);
} else if (doc.queryCommandSupported && doc.queryCommandSupported('copy')) { } else if (doc.queryCommandSupported && doc.queryCommandSupported('copy')) {
const textarea = doc.createElement('textarea'); const textarea = doc.createElement('textarea');
textarea.textContent = text; textarea.textContent = text;