diff --git a/website/assets/js/pages/docs/basic-documentation.page.js b/website/assets/js/pages/docs/basic-documentation.page.js index c5b6e046f..34a67de36 100644 --- a/website/assets/js/pages/docs/basic-documentation.page.js +++ b/website/assets/js/pages/docs/basic-documentation.page.js @@ -159,6 +159,29 @@ parasails.registerPage('basic-documentation', { }); })(); + // Adding event handlers to the Headings on the page, allowing users to copy links by clicking on the heading. + let headingsOnThisPage = $('#body-content').find(':header'); + for(let key in Object.values(headingsOnThisPage)){ + let heading = headingsOnThisPage[key]; + $(heading).click(()=> { + // Find the child element + let linkToCopy = _.first($(heading).find('a.markdown-link')); + // If this heading has already been clicked and still has the copied class we'll just ignore this click + if(!$(heading).hasClass('copied')){ + // If the link's href is missing, we'll copy the current url (and remove any hashes) to the clipboard instead + if(linkToCopy) { + navigator.clipboard.writeText(linkToCopy.href); + } else { + navigator.clipboard.writeText(heading.baseURI.split('#')[0]); + } + // Add the copied class to the header to notify the user that the link has been copied. + $(heading).addClass('copied'); + // Remove the copied class 5 seconds later, so we can notify the user again if they re-cick on this heading + setTimeout(()=>{$(heading).removeClass('copied');}, 5000); + } + }); + } + }, // ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗ diff --git a/website/assets/styles/pages/docs/basic-documentation.less b/website/assets/styles/pages/docs/basic-documentation.less index 1b843c922..7c6dc9247 100644 --- a/website/assets/styles/pages/docs/basic-documentation.less +++ b/website/assets/styles/pages/docs/basic-documentation.less @@ -44,6 +44,33 @@ } } + .markdown-heading.copied::before { + content: 'Link copied to clipboard'; + display: flex; + font-weight: 400; + position: relative; + top: -25px; + height: 0px; + font-size: 14px; + // line-height: 14px; + color: @core-vibrant-blue; + animation-name: copiedText; + animation-duration: 4s; + animation-fill-mode: forwards; + } + .markdown-heading.copied:hover::before { + // right: -15px; + } + + @keyframes copiedText { + 0% {opacity: 0;} + 20% {opacity: 100;} + 30% {opacity: 80;} + 50% {opacity: 60;} + 70% {opacity: 40;} + 80% {opacity: 20;} + 100% {opacity: 0;} + } [purpose='search'] {