Skip to content

Add section links #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Moved js scripts and added new permalinks script, see #4
  • Loading branch information
BenCuff committed Aug 30, 2024
commit a6002980a18f05611fb520c3b20537c19174fa2c
5 changes: 3 additions & 2 deletions docs/_layouts/guidance-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!--Scripts-->
<script> {% include expandable-sections.js %} </script>
<script src="assets/scripts/expandable-sections.js"></script>
<script src="assets/scripts/permalinks.js" defer></script>

</head>
<body>
Expand Down Expand Up @@ -57,4 +58,4 @@ <h1>{{ page.title }}</h1>

</body>

</html>
</html>
Binary file added docs/assets/img/permalink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions docs/assets/scripts/permalinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Function to copy link to clipboard
function copylink(text) {
navigator.clipboard.writeText(text).then(() => {
alert(`Link copied to clipboard: ${text}`);
}).catch(err => {
console.error('Failed to copy link', err);
});
}

// Add copy link icons to all heading elements
document.querySelectorAll('h1, h2, h3, h4, h5').forEach(heading => {
// Ensure the heading has an ID for the anchor link
if (!heading.id) {
heading.id = heading.textContent.trim().toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, '');
}

// Create the icon element
const iconWrapper = document.createElement('span');
iconWrapper.className = 'permalink';
iconWrapper.title = 'Permalink';
iconWrapper.innerHTML = ' ';

// Append the icon to the heading
heading.appendChild(iconWrapper);

// Add event listener for copying the link
iconWrapper.addEventListener('click', (e) => {
e.stopPropagation(); // Prevent the click event from bubbling up
const url = `${window.location.origin}${window.location.pathname}#${heading.id}`;
copylink(url);
});
});
23 changes: 22 additions & 1 deletion docs/assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ ul, ol{
}


/*Permalinks*/
.permalink{
background-image: url('img/permalink.png');
width: 18px;
height: 18px;
opacity: 0;
margin-left: 5px;
display: inline-block;
background-size: cover;
}

h1 span, h2 span, h3 span, h4 span, h5 span {
transition: opacity 0.3s ease-in-out;
}

h1:hover span, h2:hover span, h3:hover span, h4:hover span, h5:hover span{
opacity: 0.5;
}



/*Fancy elements*/
blockquote{
margin: 1em 0 2em 0;
Expand Down Expand Up @@ -342,4 +363,4 @@ td:first-child {
@media only screen and (max-width: 985px) {
#copyright-block{display:block;}
#copyright-notice{margin-left:0; padding-left:0;}
}
}