1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-07 23:03:00 +03:00

Added experimental breadcrumb traversal

This commit is contained in:
Dan Brown
2019-02-24 15:57:35 +00:00
parent e70423c73f
commit 035a0d8efb
17 changed files with 296 additions and 11 deletions

View File

@@ -0,0 +1,60 @@
class BreadcrumbListing {
constructor(elem) {
this.elem = elem;
this.searchInput = elem.querySelector('input');
this.loadingElem = elem.querySelector('.loading-container');
this.entityListElem = elem.querySelector('.breadcrumb-listing-entity-list');
this.toggleElem = elem.querySelector('[dropdown-toggle]');
// this.loadingElem.style.display = 'none';
const entityDescriptor = elem.getAttribute('breadcrumb-listing').split(':');
this.entityType = entityDescriptor[0];
this.entityId = Number(entityDescriptor[1]);
this.toggleElem.addEventListener('click', this.onShow.bind(this));
this.searchInput.addEventListener('input', this.onSearch.bind(this));
}
onShow() {
this.loadEntityView();
}
onSearch() {
const input = this.searchInput.value.toLowerCase().trim();
const listItems = this.entityListElem.querySelectorAll('.entity-list-item');
console.log(listItems);
for (let listItem of listItems) {
const match = !input || listItem.textContent.toLowerCase().includes(input);
console.log(match);
listItem.style.display = match ? 'flex' : 'none';
}
}
loadEntityView() {
this.toggleLoading(true);
const params = {
'entity_id': this.entityId,
'entity_type': this.entityType,
};
window.$http.get('/search/entity/siblings', {params}).then(resp => {
this.entityListElem.innerHTML = resp.data;
}).catch(err => {
console.error(err);
}).then(() => {
this.toggleLoading(false);
this.onSearch();
});
}
toggleLoading(show = false) {
this.loadingElem.style.display = show ? 'block' : 'none';
}
}
export default BreadcrumbListing;

View File

@@ -6,7 +6,7 @@ class DropDown {
constructor(elem) {
this.container = elem;
this.menu = elem.querySelector('ul');
this.menu = elem.querySelector('ul, [dropdown-menu]');
this.toggle = elem.querySelector('[dropdown-toggle]');
this.setupListeners();
}

View File

@@ -21,7 +21,7 @@ import homepageControl from "./homepage-control";
import headerMobileToggle from "./header-mobile-toggle";
import listSortControl from "./list-sort-control";
import triLayout from "./tri-layout";
import breadcrumbListing from "./breadcrumb-listing";
const componentMapping = {
'dropdown': dropdown,
@@ -47,6 +47,7 @@ const componentMapping = {
'header-mobile-toggle': headerMobileToggle,
'list-sort-control': listSortControl,
'tri-layout': triLayout,
'breadcrumb-listing': breadcrumbListing,
};
window.components = {};