From 683cd099bad4040bdde05ce31e201275727e18b6 Mon Sep 17 00:00:00 2001 From: navaneethsnair1 Date: Thu, 25 Jul 2024 18:57:35 +0530 Subject: [PATCH 1/2] 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, From 02ee6db9959e666de0eb23add0d5a5c35ea5fa02 Mon Sep 17 00:00:00 2001 From: navaneethsnair1 Date: Wed, 3 Jul 2024 14:14:09 +0530 Subject: [PATCH 2/2] improvements in toc filter in docs --- src/main/content/antora_ui/src/js/01-nav.js | 6 ++++ .../src/partials/nav-menu-filter.hbs | 9 ++++++ .../antora_ui/src/partials/nav-menu.hbs | 3 ++ .../content/antora_ui/src/partials/nav.hbs | 1 + src/main/content/antora_ui/src/sass/nav.scss | 29 +++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 src/main/content/antora_ui/src/partials/nav-menu-filter.hbs 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 8458bbb65a..c9064b45c0 100644 --- a/src/main/content/antora_ui/src/js/01-nav.js +++ b/src/main/content/antora_ui/src/js/01-nav.js @@ -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){ diff --git a/src/main/content/antora_ui/src/partials/nav-menu-filter.hbs b/src/main/content/antora_ui/src/partials/nav-menu-filter.hbs new file mode 100644 index 0000000000..39e15a5ab1 --- /dev/null +++ b/src/main/content/antora_ui/src/partials/nav-menu-filter.hbs @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/src/main/content/antora_ui/src/partials/nav-menu.hbs b/src/main/content/antora_ui/src/partials/nav-menu.hbs index a38d979337..62896ac82a 100644 --- a/src/main/content/antora_ui/src/partials/nav-menu.hbs +++ b/src/main/content/antora_ui/src/partials/nav-menu.hbs @@ -1,6 +1,9 @@