You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/views/list/list_fold.js

97 lines
2.2 KiB

app.views.ListFold = class ListFold extends app.View {
static targetClass = "_list-dir";
static handleClass = "_list-arrow";
static activeClass = "open";
1 year ago
static events = { click: "onClick" };
1 year ago
static shortcuts = {
left: "onLeft",
right: "onRight",
};
11 years ago
open(el) {
if (el && !el.classList.contains(this.constructor.activeClass)) {
el.classList.add(this.constructor.activeClass);
1 year ago
$.trigger(el, "open");
}
}
11 years ago
close(el) {
if (el && el.classList.contains(this.constructor.activeClass)) {
el.classList.remove(this.constructor.activeClass);
1 year ago
$.trigger(el, "close");
}
}
11 years ago
toggle(el) {
if (el.classList.contains(this.constructor.activeClass)) {
this.close(el);
} else {
this.open(el);
}
}
11 years ago
reset() {
let el;
while ((el = this.findByClass(this.constructor.activeClass))) {
this.close(el);
}
}
11 years ago
getCursor() {
1 year ago
return (
this.findByClass(app.views.ListFocus.activeClass) ||
this.findByClass(app.views.ListSelect.activeClass)
);
}
11 years ago
onLeft() {
const cursor = this.getCursor();
if (cursor?.classList?.contains(this.constructor.activeClass)) {
this.close(cursor);
}
}
11 years ago
onRight() {
const cursor = this.getCursor();
1 year ago
if (
cursor != null
? cursor.classList.contains(this.constructor.targetClass)
: undefined
) {
this.open(cursor);
}
}
11 years ago
onClick(event) {
1 year ago
if (event.which !== 1 || event.metaKey || event.ctrlKey) {
return;
}
if (!event.pageY) {
return;
} // ignore fabricated clicks
let el = $.eventTarget(event);
1 year ago
if (el.parentNode.tagName.toUpperCase() === "SVG") {
el = el.parentNode;
}
11 years ago
if (el.classList.contains(this.constructor.handleClass)) {
$.stopEvent(event);
this.toggle(el.parentNode);
} else if (el.classList.contains(this.constructor.targetClass)) {
1 year ago
if (el.hasAttribute("href")) {
if (el.classList.contains(this.constructor.activeClass)) {
1 year ago
if (el.classList.contains(app.views.ListSelect.activeClass)) {
this.close(el);
}
} else {
this.open(el);
}
} else {
this.toggle(el);
}
}
}
};