From 8b6f92f9e907267288c9a2d757c7747b22c7bca8 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa <jelle@archlinux.org> Date: Tue, 11 May 2021 00:01:13 +0200 Subject: [PATCH] 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> --- web/template/pkg_details.php | 10 +++------- web/template/pkgbase_details.php | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index c6bb32d87..047de9a76 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -308,14 +308,10 @@ endif; </div> <script> -$(document).ready(function() { - $('.copy').click(function(e) { - var tmp = $("<input>"); - $("body").append(tmp); - tmp.val($(this).text()).select(); - document.execCommand("copy"); - tmp.remove(); +document.addEventListener('DOMContentLoaded', function() { + document.querySelector('.copy').addEventListener('click', function(e) { e.preventDefault(); + navigator.clipboard.writeText(event.target.text); }); }); </script> diff --git a/web/template/pkgbase_details.php b/web/template/pkgbase_details.php index a6857c4e7..35ad217a5 100644 --- a/web/template/pkgbase_details.php +++ b/web/template/pkgbase_details.php @@ -137,14 +137,10 @@ endif; </div> <script> -$(document).ready(function() { - $('.copy').click(function(e) { - var tmp = $("<input>"); - $("body").append(tmp); - tmp.val($(this).text()).select(); - document.execCommand("copy"); - tmp.remove(); +document.addEventListener('DOMContentLoaded', function() { + document.querySelector('.copy').addEventListener('click', function(e) { e.preventDefault(); + navigator.clipboard.writeText(event.target.text); }); }); </script> -- GitLab