Skip to content
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

Added the feature of copying the headings using link icon #70

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
34 changes: 34 additions & 0 deletions frontend/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,40 @@ document.addEventListener("DOMContentLoaded", function(event) {
});
});

document.addEventListener("DOMContentLoaded", function(event) {
const headings = document.querySelectorAll('article h2, article h3, article h4, article h5, article h6, main h2, main h3, main h4, main h5, main h6');

headings.forEach(function(heading) {
const linkIcon = document.createElement('span');
linkIcon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 22 22" id="link"><g fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"><g stroke="#fff" stroke-width="2" transform="translate(-981 -1753)"><g transform="translate(982 1754)"><path d="M8 11a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07L9.75 3.18"></path><path d="M12 9a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></g></g></g></svg>';
linkIcon.style.color = '#ffffff';
linkIcon.style.cursor = 'pointer';
linkIcon.style.position = 'relative';
linkIcon.style.left = '10px';
linkIcon.style.display = 'none';

heading.appendChild(linkIcon);

linkIcon.addEventListener('click', function(event) {
event.stopPropagation();
const id = heading.getAttribute('id');
const url = window.location.href.split('#')[0] + '#' + id;
navigator.clipboard.writeText(url);
document.getElementById(id).scrollIntoView({ behavior: 'smooth' });
});

heading.addEventListener('mouseover', function() {
linkIcon.style.display = 'inline-block'; // Show the link icon on hover
});

heading.addEventListener('mouseout', function() {
linkIcon.style.display = 'none'; // Hide the link icon when not hovering
});
});
});



document.addEventListener("DOMContentLoaded", function(event) {
enableCodeHighlighting();
enableDocSearch();
Expand Down
Loading