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

auto copy header link #4411

Merged
merged 24 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8306a1a
test
mirnawong1 Nov 7, 2023
9620322
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 8, 2023
583ffe4
updates
mirnawong1 Nov 8, 2023
6fe2e77
updates
mirnawong1 Nov 9, 2023
22bf197
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 9, 2023
d7055b2
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 10, 2023
5e6cbc4
commit message
mirnawong1 Nov 10, 2023
48817d5
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 10, 2023
efb11cf
add pop upfix
mirnawong1 Nov 10, 2023
f92efe9
fix load
mirnawong1 Nov 13, 2023
e0764c5
adding badge but broken
mirnawong1 Nov 13, 2023
4060af1
revert to original
mirnawong1 Nov 13, 2023
fae19c9
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 13, 2023
76ef638
add
mirnawong1 Nov 13, 2023
d4ea9db
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 13, 2023
dba2bfc
Update website/docs/docs/collaborate/documentation.md
mirnawong1 Nov 13, 2023
fc04876
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 15, 2023
79a6a4d
final tweaks
mirnawong1 Nov 15, 2023
df10e0c
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 15, 2023
5fad4ee
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 15, 2023
3acceed
add new eventlistener
mirnawong1 Nov 15, 2023
d879035
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 15, 2023
08cfc34
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 15, 2023
779e572
Merge branch 'current' into mwong-auto-copy-header
mirnawong1 Nov 16, 2023
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
3 changes: 3 additions & 0 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require("path");
const math = require("remark-math");
const katex = require("rehype-katex");

const { versions, versionedPages, versionedCategories } = require("./dbt-versions");
require("dotenv").config();

Expand Down Expand Up @@ -258,6 +259,8 @@ var siteSettings = {
src: "https://cdn.jsdelivr.net/npm/featherlight@1.7.14/release/featherlight.min.js",
defer: true,
},
"https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js",
"/js/headerLinkCopy.js",
"/js/gtm.js",
"/js/onetrust.js",
"https://kit.fontawesome.com/7110474d41.js",
Expand Down
39 changes: 39 additions & 0 deletions website/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,45 @@ html[data-theme="dark"] .theme-doc-sidebar-container>div>button.button:hover {
color: #818589; /* You can adjust the color as needed */
}

h3.anchor a.hash-link:before,
h2.anchor a.hash-link:before {
content: "";
background-image: url('/img/copy.png');
background-size: 18px 18px;
height: 18px;
width: 18px;
display: inline-block;
}

h3.anchor.clicked a.hash-link:before,
h2.anchor.clicked a.hash-link:before {
background-image: url('/img/check.png');
background-size: 18px 13px;
height: 13px;
}

.copy-popup {
position: fixed;
top: 10px;
left: 50%;
transform: translateX(-50%);
background-color: #047377;
color: rgb(236, 236, 236);
padding: 10px;
border-radius: 5px;
z-index: 9999;
}

.close-button {
cursor: pointer;
margin: 0 10px;
font-size: 20px;
}

.close-button:hover {
color: #fff; /* Change color on hover if desired */
}

@media (max-width: 996px) {
.quickstart-container {
flex-direction: column;
Expand Down
Binary file added website/static/img/check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/static/img/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions website/static/js/headerLinkCopy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* eslint-disable */

// Get all the headers with anchor links.
// The 'click' event worked over 'popstate' because click captures page triggers, as well as back/forward button triggers
// Adding the 'load' event to also capture the initial page load
window.addEventListener("click", copyHeader);
mirnawong1 marked this conversation as resolved.
Show resolved Hide resolved
window.addEventListener("load", copyHeader);

// separating function from eventlistener to understand they are two separate things
function copyHeader () {
const headers = document.querySelectorAll("h2.anchor, h3.anchor");

headers.forEach((header) => {
header.style.cursor = "pointer";
const clipboard = new ClipboardJS(header, {
text: function(trigger) {
const anchorLink = trigger.getAttribute("id");
return window.location.href.split('#')[0] + '#' + anchorLink;
}
});

clipboard.on('success', function(e) {
// Provide user feedback (e.g., alert or tooltip) here
const popup = document.createElement('div');
popup.classList.add('copy-popup');
popup.innerText = 'Link copied!';
document.body.appendChild(popup);

// Set up timeout to remove the popup after 3 seconds
setTimeout(() => {
document.body.removeChild(popup);
}, 3000);

// Add close button ('x')
const closeButton = document.createElement('span');
closeButton.classList.add('close-button');
closeButton.innerHTML = ' ×'; // '×' symbol for 'x'
closeButton.addEventListener('click', () => {
if (document.body.contains(popup)) {
document.body.removeChild(popup);
}
});
popup.appendChild(closeButton);

// Add and remove the 'clicked' class for styling purposes
e.trigger.classList.add("clicked");
setTimeout(() => {
if (document.body.contains(popup)) {
document.body.removeChild(popup);
}
}, 3000);
});

clipboard.on('error', function(e) {
console.error("Unable to copy to clipboard: " + e.text);
});
});
};