From f2b6d7862c3e6af142738e8988877f9ab957fadb Mon Sep 17 00:00:00 2001 From: Thibaud CANALE Date: Thu, 7 Nov 2024 18:53:23 +0100 Subject: [PATCH] Use event listener for QR-Code display in CSP compliance purpose Signed-off-by: Thibaud CANALE --- plugins/qrcode/qrcode.html | 4 +--- plugins/qrcode/shaarli-qrcode.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/qrcode/qrcode.html b/plugins/qrcode/qrcode.html index a21f79328..778397173 100644 --- a/plugins/qrcode/qrcode.html +++ b/plugins/qrcode/qrcode.html @@ -1,5 +1,3 @@
- - QRCode - + QRCode
diff --git a/plugins/qrcode/shaarli-qrcode.js b/plugins/qrcode/shaarli-qrcode.js index 3316d6f63..0976564ca 100644 --- a/plugins/qrcode/shaarli-qrcode.js +++ b/plugins/qrcode/shaarli-qrcode.js @@ -51,7 +51,11 @@ function showQrCode(caller,loading) element.id = 'permalinkQrcode'; // Make QR-Code div commit sepuku when clicked: - if ( element.attachEvent ){ + if (element.addEventListener) { + element.addEventListener('click', function() { + this.parentNode.removeChild(this); + }); + } else if (element.attachEvent) { element.attachEvent('onclick', 'this.parentNode.removeChild(this);' ); } else { @@ -89,3 +93,18 @@ function removeQrcode() } return false; } + +// Create "click" event listeners for QR-Code display action +function setQrCodeClickEvent() +{ + const qrcode_collec = document.getElementsByClassName("qrcode"); + + Array.from(qrcode_collec).forEach(function(element) { + element.addEventListener('click', function() { + showQrCode(this); + return false; + }); + }); +} + +setQrCodeClickEvent();