ui: Fixed bug with Copied to clipboard.

This commit is contained in:
gerlofvanek
2024-11-15 16:58:01 +01:00
committed by tecnovert
parent 732c87b013
commit 3b86985ae3

View File

@@ -456,63 +456,63 @@
</script> </script>
{% endif %} {% endif %}
<script> <script>
function copyToClipboard(text) { let clickTimeout = null;
const el = document.createElement('textarea');
el.value = text;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
function copyAndShowMessage(elementId) { function copyToClipboard(text) {
const addressElement = document.getElementById(elementId); const el = document.createElement('textarea');
if (!addressElement) return; el.value = text;
const addressText = addressElement.innerText.trim(); document.body.appendChild(el);
copyToClipboard(addressText); el.select();
addressElement.innerText = 'Copied to clipboard'; document.execCommand('copy');
document.body.removeChild(el);
}
const originalWidth = addressElement.offsetWidth; function copyAndShowMessage(elementId) {
const addressElement = document.getElementById(elementId);
if (!addressElement) return;
const addressText = addressElement.innerText.trim();
addressElement.classList.add('copying'); if (addressText === 'Copied to clipboard') return;
addressElement.parentElement.style.width = `${originalWidth}px`; copyToClipboard(addressText);
addressElement.innerText = 'Copied to clipboard';
const originalWidth = addressElement.offsetWidth;
addressElement.classList.add('copying');
addressElement.parentElement.style.width = `${originalWidth}px`;
setTimeout(function () {
addressElement.innerText = addressText;
addressElement.classList.remove('copying');
addressElement.parentElement.style.width = '';
}, 1000);
}
setTimeout(function () { document.addEventListener('DOMContentLoaded', function() {
addressElement.innerText = addressText; const stealthAddressElement = document.getElementById('stealth_address');
addressElement.classList.remove('copying'); if (stealthAddressElement) {
addressElement.parentElement.style.width = ''; stealthAddressElement.addEventListener('click', function() {
}, 2000); copyAndShowMessage('stealth_address');
} });
}
const stealthAddressElement = document.getElementById('stealth_address'); const mainDepositAddressElement = document.getElementById('main_deposit_address');
if (stealthAddressElement) { if (mainDepositAddressElement) {
stealthAddressElement.addEventListener('click', function () { mainDepositAddressElement.addEventListener('click', function() {
copyAndShowMessage('stealth_address'); copyAndShowMessage('main_deposit_address');
}); });
} }
const moneroMainAddressElement = document.getElementById('monero_main_address');
const mainDepositAddressElement = document.getElementById('main_deposit_address'); if (moneroMainAddressElement) {
if (mainDepositAddressElement) { moneroMainAddressElement.addEventListener('click', function() {
mainDepositAddressElement.addEventListener('click', function () { copyAndShowMessage('monero_main_address');
copyAndShowMessage('main_deposit_address'); });
}); }
} const moneroSubAddressElement = document.getElementById('monero_sub_address');
if (moneroSubAddressElement) {
const moneroMainAddressElement = document.getElementById('monero_main_address'); moneroSubAddressElement.addEventListener('click', function() {
if (moneroMainAddressElement) { copyAndShowMessage('monero_sub_address');
moneroMainAddressElement.addEventListener('click', function () { });
copyAndShowMessage('monero_main_address'); }
}); });
} </script>
const moneroSubAddressElement = document.getElementById('monero_sub_address');
if (moneroSubAddressElement) {
moneroSubAddressElement.addEventListener('click', function () {
copyAndShowMessage('monero_sub_address');
});
}
</script>
<section class="p-6"> <section class="p-6">
<div class="flex items-center"> <div class="flex items-center">
<h4 class="font-semibold text-2xl text-black dark:text-white">Withdraw</h4> <h4 class="font-semibold text-2xl text-black dark:text-white">Withdraw</h4>