Debouncing inline anonymous functions does not work. This fixes all instances of that error by extracting the function or using the new `@debounce(delay)` decorator
41 lines
909 B
JavaScript
41 lines
909 B
JavaScript
import Component from "@ember/component";
|
|
import { action } from "@ember/object";
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
|
import { bind } from "discourse-common/utils/decorators";
|
|
|
|
export default Component.extend({
|
|
tagName: "",
|
|
copyIcon: "copy",
|
|
copyClass: "btn-primary",
|
|
|
|
@bind
|
|
_restoreButton() {
|
|
if (this.isDestroying || this.isDestroyed) {
|
|
return;
|
|
}
|
|
|
|
this.set("copyIcon", "copy");
|
|
this.set("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(this._restoreButton, 3000);
|
|
} catch (err) {}
|
|
},
|
|
});
|