Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs toc filter #3791

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/main/content/antora_ui/src/js/01-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ var navigation = (function(){
if (e.detail > 1) e.preventDefault();
});

$('#filter_titles').on('keyup', filterNavTitles);

$('#clear_filter').on("click", function () {
$('#filter_titles').val('');
filterNavTitles();
})
};

$('.components .versions li a').on('click', function(e){
Expand Down Expand Up @@ -153,6 +159,56 @@ var navigation = (function(){
}
}

//Filter article titles in TOC using text input
function filterNavTitles(){
let input = $('#filter_titles').val().toLowerCase();
let title_match=false;
if(input==='' ){
$('#clear_filter, .no-results-container').hide();
$(".nav-menu > .nav-list > .nav-item").addClass('is-active');
$('.nav-menu > .nav-list >.nav-item .nav-item').has('.nav-item-toggle').removeClass('is-active');
$('.nav-item').each(function() {
if ($(this).css('display') === 'none') {
$(this).css('display', '');
}
});
return;
}
$('#clear_filter').show();
let articles = $('.nav-link , .nav-menu .nav-text');
articles.parent().hide();
articles.each(function() {
let article = $(this);
let title = article.text().toLowerCase();
if (title.includes(input)) {
title_match=true;
article.parent().show();
article.parent().has('.nav-item-toggle').removeClass('is-active');
showAncestors(article.parent());
showDescendants(article.parent());
}
});
if(!title_match){
$('.no-results-container').show();
}
}

function showAncestors(item){
let parent = item.parents('.nav-item');
parent.each(function() {
$(this).show();
$(this).has('.nav-item-toggle').addClass('is-active');
});
}

function showDescendants(item) {
let children = item.find('.nav-item');
children.each(function() {
$(this).show();
$(this).has('.nav-item-toggle').removeClass('is-active');
});
}

return {
init: init,
activateCurrentPath: activateCurrentPath,
Expand Down
9 changes: 9 additions & 0 deletions src/main/content/antora_ui/src/partials/nav-menu-filter.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="nav-menu-filter" >
<input type="text" id="filter_titles" aria-label="Filter titles" placeholder="Filter titles...">
<button
id="clear_filter"
type="reset"
tabindex="0"
aria-label="Clear filter search"
>X</button>
</div>
3 changes: 3 additions & 0 deletions src/main/content/antora_ui/src/partials/nav-menu.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<div class="nav-panel-menu is-active" data-panel="menu">
<nav class="nav-menu" aria-label="Navigation menu for Open Liberty docs">
<h3 class="title"><a href="{{relativize page.componentVersion.url}}">{{page.component.title}}</a></h3>
<div class="no-results-container">
<b>No titles match</b>
</div>
{{#if page.navigation}}
{{> nav-tree navigation=page.navigation}}
{{/if}}
Expand Down
1 change: 1 addition & 0 deletions src/main/content/antora_ui/src/partials/nav.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<aside class="nav" aria-label="Navigation table of contents">
<div class="panels">
{{> nav-explore}}
{{> nav-menu-filter}}
{{> nav-menu}}
</div>
</aside>
Expand Down
29 changes: 29 additions & 0 deletions src/main/content/antora_ui/src/sass/nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,32 @@ html.is-clipped--nav {
white-space: nowrap;
display: inline-block;
}

.nav-menu-filter{
margin: 0 19px 20px;
color: #5d6a8e;
position:relative;
#filter_titles{
background-color: #eeeff3;
border: 0;
border-radius: 3px;
padding: 4px 22px 4px 0.5rem;
width: 100%;
}
#clear_filter{
position: absolute;
right: 0;
background-color: transparent;
border: 0;
top: 3px;
display: none;
}
}

.no-results-container{
display: none;
font-size: 14px;
color: #5d6a8e;
margin: 0 19px 20px;
letter-spacing: 0.2px;
}
Loading