btcpayserver/BTCPayServer/wwwroot/js/copy-to-clipboard.js
Andrew Camilleri 5ca4e71c34
Introduce QR Code View component (#2125)
* Introduce QR Code View component

* more cleanup

* fix js clipboard

* Fix clipboard confirmation width calculation

* fix tests

Co-authored-by: Dennis Reimann <mail@dennisreimann.de>
2020-12-22 11:18:51 +09:00

23 lines
928 B
JavaScript

window.copyToClipboard = function (e, text) {
if (navigator.clipboard) {
e.preventDefault();
var item = e.currentTarget;
var data = text || item.getAttribute('data-clipboard');
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;
confirm.style.minWidth = confirm.getBoundingClientRect().width + 'px';
}
navigator.clipboard.writeText(data).then(function () {
confirm.innerText = message;
setTimeout(function(){ confirm.innerText = confirm.dataset.clipboardInitialText; }, 2500);
});
item.blur();
}
}
window.copyUrlToClipboard = function (e) {
window.copyToClipboard(e, window.location);
}