Skip to content

Commit

Permalink
fix: copy
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed Apr 17, 2023
1 parent 268b5c2 commit e8a08c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
6 changes: 3 additions & 3 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<div
class="h-1/4 flex order-2 sm:order-1 justify-center items-center w-full"
>
<form method="GET" action="javascript:void 0">
<div class="w-3/4 sm:w-1/2 mx-auto">
<form class="w-full" method="GET" action="javascript:void 0">
<div class="w-3/4 sm:w-1/2 mx-auto md:mx-0">
<label class="relative w-full">
<input
id="color-input"
Expand All @@ -27,7 +27,7 @@
<button
id="color-input-button"
type="submit"
class="absolute inline-block top-1/2 right-1 px-4 py-2 rounded-md -translate-y-1/2 bg-accent text-on-accent"
class="absolute inline-block top-1/2 right-2 px-4 py-2 rounded-md -translate-y-1/2 bg-accent text-on-accent"
>
&rarr;
</button>
Expand Down
28 changes: 12 additions & 16 deletions www/js/copy.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
export function copyToClipboard(strToCopy) {
if (!navigator?.permissions?.query) {
if (!navigator?.clipboard) {
return fallBackCopy(strToCopy)
}

navigator?.permissions?.query({name: 'clipboard-write'}).then(result => {
if (result.state == 'granted' || result.state == 'prompt') {
navigator.clipboard.writeText(strToCopy).then(
function () {
// ignore and digest
},
function () {
return fallBackCopy(strToCopy)
},
)
} else {
return fallBackCopy(strToCopy)
}
})
if (navigator.clipboard) {
navigator.clipboard.writeText(strToCopy).then(
function () {
// ignore and digest
},
function () {
return fallBackCopy(strToCopy)
},
)
}
}

function fallBackCopy(strToCopy) {
Expand All @@ -29,4 +25,4 @@ function fallBackCopy(strToCopy) {
el.select()
document.execCommand('copy')
document.body.removeChild(el)
}
}
2 changes: 1 addition & 1 deletion www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"autoprefixer": "^10.4.7",
"parcel": "^2.6.0",
"postcss": "^8.4.14",
"tailwindcss": "^3.0.24"
"tailwindcss": "3.0.24"
},
"dependencies": {
"toastify-js": "^1.11.2"
Expand Down
4 changes: 2 additions & 2 deletions www/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e8a08c5

Please sign in to comment.