Skip to content

Commit

Permalink
Merge pull request #896 from zirreal/robonomics-wiki-test
Browse files Browse the repository at this point in the history
fixed copy button bug
  • Loading branch information
zirreal authored Sep 26, 2024
2 parents 478eacc + 6324c63 commit 2168828
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "wiki-rework",
"name": "robonomics-wiki",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"engines": {
Expand All @@ -19,7 +20,7 @@
},
"keywords": [],
"author": "",
"license": "ISC",
"license": "BSD-3-Clause",
"devDependencies": {
"@11ty/eleventy": "^2.0.1",
"@11ty/eleventy-img": "^4.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/components/code.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ svg path {
transition: fill 0.3s ease-in-out;
}

.copy-btn:focus svg path {
/* .copy-btn:focus svg path {
fill: rgb(59, 169, 248)
}
} */

.code-helper pre[class*=language-] {
margin-top: 0;
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/components/robo-wiki/feedback.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

.robo-wiki-feedback__checkbox {
position: absolute;
top: 15px;
top: 45px;
left: 10px;
}

Expand Down
38 changes: 22 additions & 16 deletions src/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,35 @@ document.addEventListener('DOMContentLoaded', () => {

const text = code.innerText

try {
await navigator.clipboard.writeText(text);
e.insertAdjacentHTML(
'afterend',
'<small>copied!</small>'
);
e.disabled = true
setTimeout(() => {
code.querySelector('small').remove()
e.disabled = false;
}, 3000)
} catch($e) {
code.querySelector('small').remove()
e.disabled = false;
if(!code.querySelector('small')) {
try {
await navigator.clipboard.writeText(text);
e.insertAdjacentHTML(
'afterend',
'<small>copied!</small>'
);

e.disabled = true
setTimeout(() => {
code.querySelector('small').remove()
e.disabled = false;
}, 3000)
} catch($e) {
code.querySelector('small').remove()
e.disabled = false;
}
}
}

copyBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
if(e.target === document.querySelector('button')) {
if(e.target.classList.contains('copy-btn')) {
copyCode(e.target)
} else {
copyCode(e.target.parentElement)
if(e.target.tagName.toLowerCase() === 'path') {
} else {
copyCode(e.target.parentElement)
}
}
})
})
Expand Down

0 comments on commit 2168828

Please sign in to comment.