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
4d67b4d118
commit
0d924990c8
2
public/v1/js/app.js
vendored
2
public/v1/js/app.js
vendored
File diff suppressed because one or more lines are too long
@ -161,20 +161,16 @@
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p>
|
<p>
|
||||||
<button id="copyButton" @click="copyToken" class="btn btn-default">Copy token</button>
|
<button id="copyButton" @click="copyToken" class="btn btn-default">Copy token</button>
|
||||||
</p>
|
<span id="copySuccess" style="display:none;" class="text-success">
|
||||||
<p id="copySuccess" style="display:none;" class="text-success">
|
|
||||||
Copied to clipboard!
|
Copied to clipboard!
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p id="copyError" style="display:none;" class="text-danger">
|
|
||||||
Could not copy to clipboard :(
|
|
||||||
</p>
|
|
||||||
<p>
|
<p>
|
||||||
Here is your new personal access token. This is the only time it will be shown so don't lose it!
|
Here is your new personal access token. This is the only time it will be shown so don't lose it!
|
||||||
You may now use this token to make API requests.
|
You may now use this token to make API requests.
|
||||||
</p>
|
</p>
|
||||||
|
<pre><textarea id="tokenHidden" style="width:100%;" rows="40" class="form-control">{{ accessToken }}</textarea></pre>
|
||||||
|
|
||||||
<pre><code>{{ accessToken }}</code></pre>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Modal Actions -->
|
<!-- Modal Actions -->
|
||||||
@ -224,88 +220,20 @@
|
|||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
copyToken() {
|
copyToken() {
|
||||||
this.copyToClipboard(this.accessToken);
|
/* Get the text field */
|
||||||
return;
|
var copyText = document.getElementById("tokenHidden");
|
||||||
console.log('in token thing');
|
|
||||||
if (!navigator.clipboard) {
|
|
||||||
console.log('in fallback');
|
|
||||||
this.fallbackCopyTextToClipboard(this.accessToken);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
navigator.clipboard.writeText(this.accessToken).then(function () {
|
|
||||||
//console.log('Async: Copying to clipboard was successful!');
|
|
||||||
$('#copySuccess').show();
|
|
||||||
}, function (err) {
|
|
||||||
console.error('Async: Could not copy text: ', err);
|
|
||||||
$('#copyError').show();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
fallbackCopyTextToClipboard(text) {
|
|
||||||
let textArea = document.createElement("textarea");
|
|
||||||
textArea.value = text;
|
|
||||||
document.body.appendChild(textArea);
|
|
||||||
textArea.focus();
|
|
||||||
textArea.select();
|
|
||||||
|
|
||||||
try {
|
/* Select the text field */
|
||||||
var successful = document.execCommand('copy');
|
copyText.select();
|
||||||
var msg = successful ? 'successful' : 'unsuccessful';
|
copyText.setSelectionRange(0, 2048); /*For mobile devices*/
|
||||||
successful ? $('#copySuccess').show() : $('#copyError').show();
|
|
||||||
//console.log('Fallback: Copying text command was ' + msg);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Fallback: Oops, unable to copy', err);
|
|
||||||
$('#copyError').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
document.body.removeChild(textArea);
|
/* Copy the text inside the text field */
|
||||||
},
|
document.execCommand("copy");
|
||||||
|
|
||||||
copyToClipboard(string) {
|
/* Alert the copied text */
|
||||||
let textarea;
|
$('#copyButton').hide();
|
||||||
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();
|
$('#copySuccess').show();
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the component.
|
* Prepare the component.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user