iOS compatible fix #2734

This commit is contained in:
James Cole 2019-10-14 19:22:54 +02:00
parent d57c5d3a20
commit 4d67b4d118
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 49 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -224,6 +224,8 @@
methods: {
copyToken() {
this.copyToClipboard(this.accessToken);
return;
console.log('in token thing');
if (!navigator.clipboard) {
console.log('in fallback');
@ -258,6 +260,52 @@
document.body.removeChild(textArea);
},
copyToClipboard(string) {
let textarea;
let result;
try {
textarea = document.createElement('textarea');
textarea.setAttribute('readonly', true);
textarea.setAttribute('contenteditable', true);
textarea.style.position = 'fixed'; // prevent scroll from jumping to the bottom when focus is set.
textarea.value = string;
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
const range = document.createRange();
range.selectNodeContents(textarea);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
textarea.setSelectionRange(0, textarea.value.length);
result = document.execCommand('copy');
} catch (err) {
console.error(err);
result = null;
} finally {
document.body.removeChild(textarea);
}
// manual copy fallback using prompt
if (!result) {
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
const copyHotkey = isMac ? '⌘C' : 'CTRL+C';
result = prompt(`Press ${copyHotkey}`, string); // eslint-disable-line no-alert
if (!result) {
$('#copyError').show();
return false;
}
}
$('#copySuccess').show();
return true;
},
/**
* Prepare the component.
*/