mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
iOS compatible fix #2734
This commit is contained in:
parent
d57c5d3a20
commit
4d67b4d118
File diff suppressed because one or more lines are too long
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user