mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-07 10:58:25 +02:00

* return updated HTML from bookmark actions * open details through URL * fix details update * improve modal behavior * use a frame * make behaviors properly destroy themselves * remove page and details params from tag urls * use separate behavior for details and tags * remove separate details view * make it work with other views * add asset actions * remove asset refresh for now * remove details partial * fix tests * remove old partials * update tests * cache and reuse tags * extract search autocomplete behavior * remove details param from pagination * fix tests * only return details modal when navigating in frame * fix link target * remove unused behaviors * use auto submit behavior for user select * fix import
45 lines
993 B
JavaScript
45 lines
993 B
JavaScript
import { Behavior, registerBehavior } from "./index";
|
|
|
|
class DropdownBehavior extends Behavior {
|
|
constructor(element) {
|
|
super(element);
|
|
this.opened = false;
|
|
this.onClick = this.onClick.bind(this);
|
|
this.onOutsideClick = this.onOutsideClick.bind(this);
|
|
|
|
this.toggle = element.querySelector(".dropdown-toggle");
|
|
this.toggle.addEventListener("click", this.onClick);
|
|
}
|
|
|
|
destroy() {
|
|
this.close();
|
|
this.toggle.removeEventListener("click", this.onClick);
|
|
}
|
|
|
|
open() {
|
|
this.element.classList.add("active");
|
|
document.addEventListener("click", this.onOutsideClick);
|
|
}
|
|
|
|
close() {
|
|
this.element.classList.remove("active");
|
|
document.removeEventListener("click", this.onOutsideClick);
|
|
}
|
|
|
|
onClick() {
|
|
if (this.opened) {
|
|
this.close();
|
|
} else {
|
|
this.open();
|
|
}
|
|
}
|
|
|
|
onOutsideClick(event) {
|
|
if (!this.element.contains(event.target)) {
|
|
this.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
registerBehavior("ld-dropdown", DropdownBehavior);
|