From e8b2a2943f957c27827ca1a18884390ab7a4fcc7 Mon Sep 17 00:00:00 2001 From: navaneethsnair1 Date: Thu, 25 Jul 2024 18:57:35 +0530 Subject: [PATCH] added toc-filter --- src/main/content/antora_ui/src/js/01-nav.js | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/main/content/antora_ui/src/js/01-nav.js b/src/main/content/antora_ui/src/js/01-nav.js index 44a3b1ff5e..8458bbb65a 100644 --- a/src/main/content/antora_ui/src/js/01-nav.js +++ b/src/main/content/antora_ui/src/js/01-nav.js @@ -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,