Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #335 from 18F/identify-external-links
Browse files Browse the repository at this point in the history
Identify external links with an icon
  • Loading branch information
mgwalker authored Jan 6, 2023
2 parents 2dffdf9 + 32003d3 commit 041a22b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
---
---

// ^ that up there is frontmatter tags so that Jekyll will process this file and
// replace {{ site.baseurl }} correctly. Without the frontmatter tags, Jekyll
// copies the file unedited.

document.addEventListener('DOMContentLoaded', function() {
PrivateEye({
defaultMessage: "This link is private to GSA.",
Expand Down Expand Up @@ -33,4 +40,19 @@ document.addEventListener('DOMContentLoaded', function() {
'tock.18f.gov'
]
});

const externalLinkIcon = document.createElement("img");
externalLinkIcon.setAttribute(
"src",
`{{ site.baseurl }}/assets/uswds/img/usa-icons/launch.svg`
);
externalLinkIcon.setAttribute("style", "width: 1rem;");

Array.from(document.querySelectorAll("a[href]"))
.filter((a) => {
const href = a.getAttribute("href");
return !href.startsWith(window.location.origin) && !/^[/#]/.test(a.getAttribute("href"))
})
.forEach((a) => a.appendChild(externalLinkIcon.cloneNode()));

}, false );

0 comments on commit 041a22b

Please sign in to comment.