mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-12 01:20:18 +08:00
`discourse-common` was created in the past to share logic between the 'wizard' app and the main 'discourse' app. Since then, the wizard has been consolidated into the main app, so the separation of `discourse-common` is no longer useful. This commit moves `discourse-common/(lib|utils)/*` into `discourse/lib/*`, adds shims for the imports, and updates existing uses in core.
30 lines
745 B
JavaScript
30 lines
745 B
JavaScript
import { registerDestructor } from "@ember/destroyable";
|
|
import Modifier from "ember-modifier";
|
|
import { bind } from "discourse/lib/decorators";
|
|
|
|
export default class FloatKitCloseOnEscape extends Modifier {
|
|
constructor(owner, args) {
|
|
super(owner, args);
|
|
registerDestructor(this, (instance) => instance.cleanup());
|
|
}
|
|
|
|
modify(element, [closeFn]) {
|
|
this.closeFn = closeFn;
|
|
this.element = element;
|
|
|
|
document.addEventListener("keydown", this.check, { capture: true });
|
|
}
|
|
|
|
@bind
|
|
check(event) {
|
|
if (event.key === "Escape") {
|
|
event.stopPropagation();
|
|
event.preventDefault();
|
|
this.closeFn();
|
|
}
|
|
}
|
|
|
|
cleanup() {
|
|
document.removeEventListener("keydown", this.check, { capture: true });
|
|
}
|
|
}
|