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

Enhanced copy color function #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
34 changes: 15 additions & 19 deletions js/copyColor.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
$(document).ready(function() {
$('.color-box').click(function() {

//Temp. input to copy color to clip Board
let temp1 = $("<input>");
$("body").append(temp1);
temp1.val($(this).text().trim()).select();
document.execCommand("copy");
temp1.remove();
//Temp. input to copy color to clip Board
if($(this).find('.hex-number').text() !== 'Copied!') {
let temp1 = $("<input>");
$("body").append(temp1);
temp1.val($(this).find('.hex-number').text()).select();
document.execCommand("copy");
temp1.remove();
}

//Temp. <p> for displaying "color copied !"
let temp2 = $("<p>");
temp2.css({
"font-weight": "bold",
"position": "absolute",
"top": "10px",
"left": "50%",
"transform": "translateX(-50%)"
})
$(this).append(temp2);
temp2.html('Color Copied !');
temp2.fadeIn().delay(1000).fadeOut();
//Changing hexNumber to "Copied!"
let hexNumber;
if($(this).find('.hex-number').text() !== 'Copied!') {
hexNumber = $(this).find('.hex-number').text();
}
$(this).find('.hex-number').text('Copied!');
setTimeout(() => {
temp2.remove();
$(this).find('.hex-number').text(hexNumber);
}, 1000);
});
});