This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/components/copy-button.js
Kris aebc6164fc
UX: Add success state to copy button (#13691)
Replaces the message "Topic link copied" with a more intuitive delayed change of the copy button to a success tick.
2021-07-12 10:47:24 +10:00

34 lines
829 B
JavaScript

import Component from "@ember/component";
import { action } from "@ember/object";
import discourseDebounce from "discourse-common/lib/debounce";
export default Component.extend({
tagName: "",
copyIcon: "copy",
copyClass: "btn-primary",
@action
copy() {
const target = document.querySelector(this.selector);
target.select();
target.setSelectionRange(0, target.value.length);
try {
document.execCommand("copy");
if (this.copied) {
this.copied();
}
this.set("copyIcon", "check");
this.set("copyClass", "btn-primary ok");
discourseDebounce(() => {
if (this.isDestroying || this.isDestroyed) {
return;
}
this.set("copyIcon", "copy");
this.set("copyClass", "btn-primary");
}, 3000);
} catch (err) {}
},
});