Skip to content

Commit

Permalink
Use more efficient copy method for clipboard service
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa authored and MarcEgliP committed Jul 21, 2023
1 parent ca16937 commit 7fd3605
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions frontend/app/services/clipboard-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ import Service from "@ember/service";

export default class ClipboardService extends Service {
copy(text) {
// Copying to clipboard is not possible in another way. Even libraries do it with a fake element.
// We don't use the addon ember-cli-clipboard, as we need to wait for a async call to finish.
const fakeEl = document.createElement("textarea");
fakeEl.value = text;
fakeEl.setAttribute("readonly", "");
fakeEl.style.position = "absolute";
fakeEl.style.left = "-9999px";
document.body.appendChild(fakeEl);
fakeEl.select();
document.execCommand("copy");
document.body.removeChild(fakeEl);
navigator.clipboard.writeText(text);
}
}

0 comments on commit 7fd3605

Please sign in to comment.