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

feat: Add alt optional copy HTML to clipboard on demo site #608

Merged
merged 3 commits into from
Oct 3, 2023
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
2 changes: 1 addition & 1 deletion src/demo/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ input:focus:invalid {
border-left: 4px solid var(--yellow);
}

.output .md,
.output .code-container,
.output .json {
background: var(--border);
border-radius: 6px;
Expand Down
25 changes: 19 additions & 6 deletions src/demo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,27 @@ function gtag() {
Note: The stats above are just examples and not from your GitHub profile.
</p>

<h2>Markdown</h2>
<div class="md">
<code></code>
<div>
<h2>Markdown</h2>
<div class="code-container md">
<code></code>
</div>

<button class="copy-button btn tooltip copy-md" onclick="clipboard.copy(this);" onmouseout="tooltip.reset(this);" disabled>
Copy To Clipboard
</button>
</div>

<button class="copy-button btn tooltip" onclick="clipboard.copy(this);" onmouseout="tooltip.reset(this);" disabled>
Copy To Clipboard
</button>
<div>
<h2>HTML</h2>
<div class="code-container html">
<code></code>
</div>

<button class="copy-button btn tooltip copy-html" onclick="clipboard.copy(this);" onmouseout="tooltip.reset(this);" disabled>
Copy To Clipboard
</button>
</div>
</div>
<div class="bottom">
<a href="https://github.com/DenverCoder1/github-readme-streak-stats/blob/main/docs/faq.md" target="_blank" class="underline-hover faq">
Expand Down
15 changes: 12 additions & 3 deletions src/demo/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ const preview = {
if (params.type !== "json") {
const repoLink = "https://git.io/streak-stats";
const md = `[![GitHub Streak](${imageURL})](${repoLink})`;
const html = `<a href="${repoLink}"><img src="${imageURL}" alt="Readme Streak Stats" /></a>`;
document.querySelector(".output img").src = demoImageURL;
document.querySelector(".md code").innerText = md;
document.querySelector(".html code").innerText = html;
document.querySelector(".output img").style.display = "block";
document.querySelector(".output .json").style.display = "none";
} else {
Expand All @@ -55,10 +57,13 @@ const preview = {
.then((data) => (document.querySelector(".output .json pre").innerText = JSON.stringify(data, null, 2)))
.catch(console.error);
document.querySelector(".md code").innerText = imageURL;
document.querySelector(".html code").innerText = imageURL;
}
// disable copy button if username is invalid
const copyButton = document.querySelector(".copy-button");
copyButton.disabled = Boolean(document.querySelector("#user:invalid") || !document.querySelector("#user").value);
const copyButtons = document.querySelectorAll(".copy-button");
copyButtons.forEach(button => {
button.disabled = Boolean(document.querySelector("#user:invalid") || !document.querySelector("#user").value);
});
// disable clear button if no added advanced options
const clearButton = document.querySelector("#clear-button");
clearButton.disabled = !document.querySelectorAll(".minus").length;
Expand Down Expand Up @@ -379,7 +384,11 @@ const clipboard = {
copy(el) {
// create input box to copy from
const input = document.createElement("input");
input.value = document.querySelector(".md code").innerText;
if (el.classList.contains("copy-md")) {
input.value = document.querySelector(".md code").innerText;
} else if (el.classList.contains("copy-html")) {
input.value = document.querySelector(".html code").innerText;
}
document.body.appendChild(input);
// select all
input.select();
Expand Down