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