Skip to content

Commit

Permalink
fix copy support
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Hardman <[email protected]>
  • Loading branch information
dhh1128 committed Sep 6, 2024
1 parent 444c271 commit 0c67878
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
16 changes: 16 additions & 0 deletions assets/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,21 @@ button:hover {
background-color: #baa8a1;
}
label.copier {
background-repeat: no-repeat;
background-position: right bottom 4px;
background-image: url("{{ site.baseurl }}/assets/copy-icon.png");
}
@keyframes copiedAnimation {
0% {
background-color: initial; /* Start with the initial color */
}
50% {
background-color: #ecd1c1; /* At 50%, the background becomes beige */
}
100% {
background-color: initial; /* Return to the original color */
}
}
.copied {
animation: copiedAnimation 0.5s ease-in-out;
}
14 changes: 10 additions & 4 deletions form.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@
return;
}
// Copy the value of the element with the ID specified in the "for" attribute
const forAttribute = this.getAttribute('for');
const targetElement = document.getElementById(forAttribute);
const value = targetElement.value;
const forAttr = this.getAttribute('for');
const target = document.getElementById(forAttr);
const value = target.value;
navigator.clipboard.writeText(value).then(() => {
console.log('Value copied to clipboard:', value);
// Add the animation class to the textarea
target.classList.add('copied');
// Remove the animation class after the animation ends (0.5s in this case)
setTimeout(function() {
target.classList.remove('copied');
}, 500);
})
.catch((error) => {
console.error('Failed to copy value to clipboard:', error);
Expand All @@ -84,5 +90,5 @@
// Add event listener to each label
labels.forEach(label => {
label.addEventListener('click', copyValue);
});
});
</script>

0 comments on commit 0c67878

Please sign in to comment.