From a0aba7129150acdde0af7fe1570f659581a68706 Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Thu, 24 Aug 2023 17:19:12 +0200 Subject: [PATCH] Add: js script for external link confirmation --- archivist/static/js/confirm_external_links.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 archivist/static/js/confirm_external_links.js diff --git a/archivist/static/js/confirm_external_links.js b/archivist/static/js/confirm_external_links.js new file mode 100644 index 0000000..3c95b5e --- /dev/null +++ b/archivist/static/js/confirm_external_links.js @@ -0,0 +1,29 @@ +// static/js/confirm_external_links.js + +document.addEventListener("DOMContentLoaded", function () { + var externalLinks = document.querySelectorAll("a[href^='http']:not([href*='" + window.location.host + "'])"); + + for (var i = 0; i < externalLinks.length; i++) { + externalLinks[i].addEventListener("click", function (event) { + event.preventDefault(); + var confirmationModal = new bootstrap.Modal(document.getElementById('externalLinkConfirmationModal'), { + keyboard: false + }); + + var externalLink = document.getElementById('externalLink'); + var externalLinkShow = document.getElementById('externalLinkShow'); + var originalLink = this.href; + + externalLink.setAttribute('href', originalLink); + + externalLinkShow.innerText = "URL: " + this.href; + + confirmationModal.show(); + + externalLink.addEventListener('click', function () { + confirmationModal.hide(); + + }); + }); + } +}); \ No newline at end of file