Replaces the message "Topic link copied" with a more intuitive delayed change of the copy button to a success tick.
34 lines
829 B
JavaScript
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) {}
|
|
},
|
|
});
|