Skip to content

Commit

Permalink
added toc-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
navaneethsnair1 committed Jul 31, 2024
1 parent a2f00e4 commit e8b2a29
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 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 @@ -153,6 +153,57 @@ 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;
$('.no-results-container').hide();
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

0 comments on commit e8b2a29

Please sign in to comment.