UX: Add copied text upon copy button click (#9793)

This commit is contained in:
Justin DiRose 2020-05-15 10:08:46 -05:00 committed by GitHub
parent 3a615a8bdd
commit 9810ca1dbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import { withPluginApi } from "discourse/lib/plugin-api";
import { cancel, later } from "@ember/runloop";
import { Promise } from "rsvp";
import { iconHTML } from "discourse-common/lib/icon-library";
import I18n from "I18n";
// http://github.com/feross/clipboard-copy
function clipboardCopy(text) {
@ -86,6 +87,8 @@ export default {
if (code) {
clipboardCopy(code.innerText.trim()).then(() => {
button.classList.add("copied");
const state = button.innerHTML;
button.innerHTML = I18n.t("copy_codeblock.copied");
const commandId = Ember.guidFor(button);
@ -96,6 +99,7 @@ export default {
_fadeCopyCodeblocksRunners[commandId] = later(() => {
button.classList.remove("copied");
button.innerHTML = state;
delete _fadeCopyCodeblocksRunners[commandId];
}, 3000);
});

View File

@ -336,6 +336,9 @@ en:
tomorrow_with_time: "tomorrow at %{time}"
at_time: "at %{date_time}"
existing_reminder: "You have a reminder set for this bookmark which will be sent"
copy_codeblock:
copied: "copied!"
drafts:
resume: "Resume"