mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-10 07:55:24 +02:00
filter for section added
This commit is contained in:
parent
8fd0b7a820
commit
1af4e05027
1 changed files with 59 additions and 47 deletions
|
@ -64,13 +64,13 @@ export default class SidebarFilter {
|
|||
// Initialize search input.
|
||||
this.search.value = '';
|
||||
// Initialize the search results.
|
||||
this.filterSections('');
|
||||
this.filter('');
|
||||
|
||||
// Add event listener for search input.
|
||||
this.search.addEventListener('input', e => {
|
||||
e.stopImmediatePropagation();
|
||||
e.preventDefault();
|
||||
this.filterSections(e.target.value);
|
||||
this.filter(e.target.value);
|
||||
});
|
||||
// Add event listener for keyboard events.
|
||||
this.search.addEventListener('keydown', e => this.handleKeyboardEvent(e));
|
||||
|
@ -260,26 +260,21 @@ export default class SidebarFilter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Filter sidebar items.
|
||||
* filter sidebar items.
|
||||
*
|
||||
* @param {HTMLElement} section - Section element.
|
||||
* @param {string} searchValue - Search value.
|
||||
*/
|
||||
filterSections(searchValue) {
|
||||
// remove selection from previous search results.
|
||||
this.blurTitleOrItem(this.selectedSearchResultIndex);
|
||||
// empty selected index.
|
||||
this.selectedSearchResultIndex = null;
|
||||
// empty search results.
|
||||
this.searchResults = [];
|
||||
// match search value with sidebar sections.
|
||||
this.sections.forEach(section => {
|
||||
filterSection(section, searchValue) {
|
||||
// match with section title.
|
||||
const sectionTitle = section.querySelector('.' + SidebarFilter.CSS.sectionTitle);
|
||||
const sectionList = section.querySelector('.' + SidebarFilter.CSS.sectionList);
|
||||
|
||||
// check if section title matches.
|
||||
const isTitleMatch = sectionTitle.innerText.trim().toLowerCase()
|
||||
.indexOf(searchValue.toLowerCase()) !== -1;
|
||||
const matchResults = [];
|
||||
// match with section items.
|
||||
const sectionList = section.querySelector('.' + SidebarFilter.CSS.sectionList);
|
||||
let isSingleItemMatch = false;
|
||||
|
||||
if (sectionList) {
|
||||
|
@ -314,6 +309,23 @@ export default class SidebarFilter {
|
|||
type: 'title',
|
||||
}, ...matchResults);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter sidebar sections.
|
||||
*
|
||||
* @param {string} searchValue - Search value.
|
||||
*/
|
||||
filter(searchValue) {
|
||||
// remove selection from previous search results.
|
||||
this.blurTitleOrItem(this.selectedSearchResultIndex);
|
||||
// empty selected index.
|
||||
this.selectedSearchResultIndex = null;
|
||||
// empty search results.
|
||||
this.searchResults = [];
|
||||
// match search value with sidebar sections.
|
||||
this.sections.forEach(section => {
|
||||
this.filterSection(section, searchValue);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue