Skip to content

Commit ba294a1

Browse files
committed
Use navigator.clipboard.writeText
1 parent 34220e6 commit ba294a1

File tree

2 files changed

+3
-22
lines changed

2 files changed

+3
-22
lines changed

Diff for: assets/javascripts/lib/util.js

-18
Original file line numberDiff line numberDiff line change
@@ -526,21 +526,3 @@ $.highlight = function (el, options) {
526526
el.classList.add(options.className);
527527
setTimeout(() => el.classList.remove(options.className), options.delay);
528528
};
529-
530-
$.copyToClipboard = function (string) {
531-
let result;
532-
const textarea = document.createElement("textarea");
533-
textarea.style.position = "fixed";
534-
textarea.style.opacity = 0;
535-
textarea.value = string;
536-
document.body.appendChild(textarea);
537-
try {
538-
textarea.select();
539-
result = !!document.execCommand("copy");
540-
} catch (error) {
541-
result = false;
542-
} finally {
543-
document.body.removeChild(textarea);
544-
}
545-
return result;
546-
};

Diff for: assets/javascripts/views/content/entry_page.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,9 @@ app.views.EntryPage = class EntryPage extends app.View {
217217
this.load();
218218
} else if (target.classList.contains("_pre-clip")) {
219219
$.stopEvent(event);
220-
target.classList.add(
221-
$.copyToClipboard(target.parentNode.textContent)
222-
? "_pre-clip-success"
223-
: "_pre-clip-error",
220+
navigator.clipboard.writeText(target.parentNode.textContent).then(
221+
() => target.classList.add("_pre-clip-success"),
222+
() => target.classList.add("_pre-clip-error"),
224223
);
225224
setTimeout(() => (target.className = "_pre-clip"), 2000);
226225
}

0 commit comments

Comments
 (0)