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();
if (addressText === 'Copied to clipboard') return;
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);
}
addressElement.classList.add('copying'); document.addEventListener('DOMContentLoaded', function() {
const stealthAddressElement = document.getElementById('stealth_address');
addressElement.parentElement.style.width = `${originalWidth}px`; if (stealthAddressElement) {
stealthAddressElement.addEventListener('click', function() {
setTimeout(function () { copyAndShowMessage('stealth_address');
addressElement.innerText = addressText; });
addressElement.classList.remove('copying'); }
addressElement.parentElement.style.width = ''; const mainDepositAddressElement = document.getElementById('main_deposit_address');
}, 2000); if (mainDepositAddressElement) {
} mainDepositAddressElement.addEventListener('click', function() {
copyAndShowMessage('main_deposit_address');
const stealthAddressElement = document.getElementById('stealth_address'); });
if (stealthAddressElement) { }
stealthAddressElement.addEventListener('click', function () { const moneroMainAddressElement = document.getElementById('monero_main_address');
copyAndShowMessage('stealth_address'); if (moneroMainAddressElement) {
}); moneroMainAddressElement.addEventListener('click', function() {
} copyAndShowMessage('monero_main_address');
});
const mainDepositAddressElement = document.getElementById('main_deposit_address'); }
if (mainDepositAddressElement) { const moneroSubAddressElement = document.getElementById('monero_sub_address');
mainDepositAddressElement.addEventListener('click', function () { if (moneroSubAddressElement) {
copyAndShowMessage('main_deposit_address'); moneroSubAddressElement.addEventListener('click', function() {
}); copyAndShowMessage('monero_sub_address');
} });
}
const moneroMainAddressElement = document.getElementById('monero_main_address'); });
if (moneroMainAddressElement) { </script>
moneroMainAddressElement.addEventListener('click', function () {
copyAndShowMessage('monero_main_address');
});
}
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>