mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-22 11:23:02 +00:00
1b7731e506
* add destroy hook * refresh details modal in interval * refactor to refresh assets list * disable create snapshot button when there is a pending snapshot
36 lines
840 B
JavaScript
36 lines
840 B
JavaScript
import { Behavior, registerBehavior } from "./index";
|
|
|
|
class DropdownBehavior extends Behavior {
|
|
constructor(element) {
|
|
super(element);
|
|
this.opened = false;
|
|
this.onOutsideClick = this.onOutsideClick.bind(this);
|
|
|
|
const toggle = element.querySelector(".dropdown-toggle");
|
|
toggle.addEventListener("click", () => {
|
|
if (this.opened) {
|
|
this.close();
|
|
} else {
|
|
this.open();
|
|
}
|
|
});
|
|
}
|
|
|
|
open() {
|
|
this.element.classList.add("active");
|
|
document.addEventListener("click", this.onOutsideClick);
|
|
}
|
|
|
|
close() {
|
|
this.element.classList.remove("active");
|
|
document.removeEventListener("click", this.onOutsideClick);
|
|
}
|
|
|
|
onOutsideClick(event) {
|
|
if (!this.element.contains(event.target)) {
|
|
this.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
registerBehavior("ld-dropdown", DropdownBehavior);
|