Skip to content

Commit

Permalink
Add custom style and behaviour on external link
Browse files Browse the repository at this point in the history
Resolves #190
  • Loading branch information
oodamien committed Nov 2, 2023
1 parent 379fb35 commit d6739c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/css/doc.css
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,7 @@ h1.page + aside.toc.embedded {
background: var(--kbd-background);
border: 1px solid var(--kbd-border-color);
border-radius: 0.25em;
box-shadow:
0 1px 0 var(--kbd-border-color),
0 0 0 0.1em var(--body-background) inset;
box-shadow: 0 1px 0 var(--kbd-border-color), 0 0 0 0.1em var(--body-background) inset;
padding: 0.25em 0.5em;
vertical-align: text-bottom;
white-space: nowrap; /* effectively ignores hyphens setting */
Expand Down Expand Up @@ -807,3 +805,14 @@ html.dark-theme .doc img {
padding: 1rem;
padding-top: 0;
}

.doc a.external::after {
content: "\f08e";
margin-left: 4px;
display: inline-block;
font: normal normal normal 14px/1 FontAwesome, sans-serif;
font-size: 12px;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
11 changes: 11 additions & 0 deletions src/js/02-on-this-page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
;(function () {
'use strict'

document.querySelectorAll('.content article a')
.forEach(function (item) {
const location = window.location
if (location) {
if (item.hostname && item.hostname !== location.hostname) {
item.classList.add('external')
item.setAttribute('target', '_blank')
}
}
})

var sidebar = document.querySelector('div.toc')
if (!sidebar) return
if (document.querySelector('body.-toc')) return sidebar.parentNode.removeChild(sidebar)
Expand Down

0 comments on commit d6739c7

Please sign in to comment.