Use the clipboard API for copy paste

The Document.execCommand API is deprecated and no longer recommended to
be used. It's replacement is the much simpler navigator.clipboard API
which is supported in all browsers except internet explorer.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
This commit is contained in:
Jelle van der Waa 2021-05-11 00:01:13 +02:00 committed by Eli Schwartz
parent 8d9f20939c
commit 8b6f92f9e9
No known key found for this signature in database
GPG key ID: CEB167EFB5722BD6
2 changed files with 6 additions and 14 deletions

View file

@ -308,14 +308,10 @@ endif;
</div> </div>
<script> <script>
$(document).ready(function() { document.addEventListener('DOMContentLoaded', function() {
$('.copy').click(function(e) { document.querySelector('.copy').addEventListener('click', function(e) {
var tmp = $("<input>");
$("body").append(tmp);
tmp.val($(this).text()).select();
document.execCommand("copy");
tmp.remove();
e.preventDefault(); e.preventDefault();
navigator.clipboard.writeText(event.target.text);
}); });
}); });
</script> </script>

View file

@ -137,14 +137,10 @@ endif;
</div> </div>
<script> <script>
$(document).ready(function() { document.addEventListener('DOMContentLoaded', function() {
$('.copy').click(function(e) { document.querySelector('.copy').addEventListener('click', function(e) {
var tmp = $("<input>");
$("body").append(tmp);
tmp.val($(this).text()).select();
document.execCommand("copy");
tmp.remove();
e.preventDefault(); e.preventDefault();
navigator.clipboard.writeText(event.target.text);
}); });
}); });
</script> </script>