Add copy link confirmation

This commit is contained in:
Dennis Reimann 2020-10-03 17:04:36 +02:00
parent eb9dc95c58
commit dcf8783c2e
No known key found for this signature in database
GPG Key ID: 5009E1797F03F8D0
5 changed files with 29 additions and 9 deletions

View File

@ -29,9 +29,9 @@
@if (env.OnionUrl != null)
{
<div class="text-center">
<a href="@env.OnionUrl" target="_onion" class="btn btn-sm btn-outline-onion d-inline-flex align-items-center text-nowrap p-2" data-clipboard="@env.OnionUrl">
<a href="@env.OnionUrl" target="_onion" class="btn btn-sm btn-outline-onion d-inline-flex align-items-center text-nowrap p-2" data-clipboard="@env.OnionUrl" style="min-width:117px;">
<img src="~/img/icons/onion-purple.svg" height="20" class="mr-2" asp-append-version="true" />
Copy Tor URL
<span data-clipboard-confirm="Copied URL ✔">Copy Tor URL</span>
</a>
</div>
}

View File

@ -33,9 +33,9 @@
@if (env.OnionUrl != null)
{
<div class="text-center">
<a href="@env.OnionUrl" target="_onion" class="btn btn-sm btn-outline-onion d-inline-flex align-items-center text-nowrap p-2" data-clipboard="@env.OnionUrl">
<a href="@env.OnionUrl" target="_onion" class="btn btn-sm btn-outline-onion d-inline-flex align-items-center text-nowrap p-2" data-clipboard="@env.OnionUrl" style="min-width:117px;">
<img src="~/img/icons/onion-purple.svg" height="20" class="mr-2" asp-append-version="true" />
Copy Tor URL
<span data-clipboard-confirm="Copied URL ✔">Copy Tor URL</span>
</a>
</div>
}

View File

@ -192,8 +192,13 @@
document.getElementById("copyLink").addEventListener("click", function (e) {
if (navigator.clipboard) {
e.preventDefault();
navigator.clipboard.writeText(window.location);
e.currentTarget.blur();
var button = e.currentTarget;
if (!button.dataset.initialText) button.dataset.initialText = button.innerText;
navigator.clipboard.writeText(window.location).then(function () {
button.innerText = 'Copied ✔';
setTimeout(function() { button.innerText = button.dataset.initialText; }, 2500);
});
button.blur();
}
});
</script>

View File

@ -85,7 +85,17 @@ $(function () {
e.preventDefault();
var item = e.currentTarget;
var text = item.getAttribute('data-clipboard');
navigator.clipboard.writeText(text);
var confirm = item.querySelector('[data-clipboard-confirm]') || item;
var message = confirm.getAttribute('data-clipboard-confirm') || 'Copied ✔';
if (!confirm.dataset.clipboardInitialText) {
confirm.dataset.clipboardInitialText = confirm.innerText;
console.log(confirm.clientWidth)
confirm.style.minWidth = confirm.clientWidth + 'px';
}
navigator.clipboard.writeText(text).then(function () {
confirm.innerText = message;
setTimeout(function(){ confirm.innerText = confirm.dataset.clipboardInitialText; }, 2500);
});
item.blur();
}
});

View File

@ -87,8 +87,13 @@ addLoadEvent(function (ev) {
copyLink: function (e) {
if (navigator.clipboard) {
e.preventDefault();
navigator.clipboard.writeText(window.location);
e.currentTarget.blur();
var button = e.currentTarget;
if (!button.dataset.initialText) button.dataset.initialText = button.innerText;
navigator.clipboard.writeText(window.location).then(function () {
button.innerText = 'Copied ✔';
setTimeout(function() { button.innerText = button.dataset.initialText; }, 2500);
});
button.blur();
}
},
cancelPayment: function (amount) {