mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 16:23:48 +08:00
48193767bf
Automatically generated by `eslint --fix` to satisfy the updated configuration
39 lines
873 B
JavaScript
39 lines
873 B
JavaScript
import { registerDestructor } from "@ember/destroyable";
|
|
import Modifier from "ember-modifier";
|
|
import { bind } from "discourse-common/utils/decorators";
|
|
|
|
export default class FloatKitCloseOnClickOutside extends Modifier {
|
|
constructor(owner, args) {
|
|
super(owner, args);
|
|
registerDestructor(this, (instance) => instance.cleanup());
|
|
}
|
|
|
|
modify(element, [trigger, closeFn]) {
|
|
this.closeFn = closeFn;
|
|
this.trigger = trigger;
|
|
this.element = element;
|
|
document.addEventListener("click", this.check, {
|
|
passive: true,
|
|
});
|
|
}
|
|
|
|
@bind
|
|
check(event) {
|
|
if (this.element.contains(event.target)) {
|
|
return;
|
|
}
|
|
if (
|
|
this.trigger instanceof HTMLElement &&
|
|
this.trigger.contains(event.target)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
this.closeFn();
|
|
}
|
|
|
|
cleanup() {
|
|
document.removeEventListener("click", this.check);
|
|
}
|
|
}
|