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/sidebar/results.js

95 lines
2.0 KiB

app.views.Results = class Results extends app.View {
static className = "_list";
1 year ago
static events = { click: "onClick" };
1 year ago
static routes = { after: "afterRoute" };
11 years ago
1 year ago
constructor(sidebar, search) {
super();
1 year ago
this.sidebar = sidebar;
this.search = search;
this.init0(); // needs this.search
this.refreshElements();
1 year ago
}
deactivate() {
if (super.deactivate(...arguments)) {
this.empty();
}
}
11 years ago
init0() {
1 year ago
this.addSubview((this.listFocus = new app.views.ListFocus(this.el)));
this.addSubview((this.listSelect = new app.views.ListSelect(this.el)));
11 years ago
this.search
.on("results", (entries, flags) => this.onResults(entries, flags))
.on("noresults", () => this.onNoResults())
.on("clear", () => this.onClear());
}
11 years ago
onResults(entries, flags) {
1 year ago
if (flags.initialResults) {
this.listFocus?.blur();
1 year ago
}
if (flags.initialResults) {
this.empty();
}
this.append(this.tmpl("sidebarResult", entries));
11 years ago
if (flags.initialResults) {
1 year ago
if (flags.urlSearch) {
this.openFirst();
} else {
this.focusFirst();
}
}
}
11 years ago
onNoResults() {
1 year ago
this.html(this.tmpl("sidebarNoResults"));
}
11 years ago
onClear() {
this.empty();
}
11 years ago
focusFirst() {
1 year ago
if (!app.isMobile()) {
this.listFocus?.focusOnNextFrame(this.el.firstElementChild);
1 year ago
}
}
openFirst() {
this.el.firstElementChild?.click();
}
11 years ago
onDocEnabled(doc) {
app.router.show(doc.fullPath());
return this.sidebar.onDocEnabled();
}
11 years ago
afterRoute(route, context) {
1 year ago
if (route === "entry") {
this.listSelect.selectByHref(context.entry.fullPath());
} else {
this.listSelect.deselect();
}
}
11 years ago
onClick(event) {
let slug;
1 year ago
if (event.which !== 1) {
return;
}
if ((slug = $.eventTarget(event).getAttribute("data-enable"))) {
$.stopEvent(event);
1 year ago
const doc = app.disabledDocs.findBy("slug", slug);
if (doc) {
return app.enableDoc(doc, this.onDocEnabled.bind(this, doc), $.noop);
}
}
}
};