Skip to content

Commit

Permalink
Config Doc - Improve section handling in search
Browse files Browse the repository at this point in the history
We used to display the previous section even if it wasn't really
related.
This should be a lot better now.
  • Loading branch information
gsmet committed Sep 9, 2024
1 parent 22c31d8 commit 864e22f
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions docs/src/main/asciidoc/javascript/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ function findText(row, search){
var elementText = n.nodeValue;
if(elementText == undefined)
continue;
if(elementText.toLowerCase().indexOf(search) != -1
if((elementText.toLowerCase().indexOf(search) != -1
|| elementText.toLowerCase().indexOf(search.replace(" ", "-")) != -1)
// check that it's not decoration
&& acceptTextForSearch(n)){
iter.detach();
Expand Down Expand Up @@ -198,11 +199,15 @@ function search(input){
function applySearch(table, search, autoExpand){
// clear highlights
clearHighlights(table);
var lastExtensionHeader = null;
var lastConfigRootHeader = null;
var lastSectionHeader = null;
var idx = 0;
for (var row of table.querySelectorAll("table.configuration-reference > tbody > tr")) {
var heads = row.querySelectorAll("table.configuration-reference > tbody > tr > th");
if(!heads || heads.length == 0){
var isExtensionNameRow = row.querySelectorAll("th span.extension-name").length > 0;
var isConfigRootNameRow = row.querySelectorAll("th span.configroot-name").length > 0;
var isSectionNameRow = row.querySelectorAll("th span.section-name").length > 0;
if(!isExtensionNameRow && !isConfigRootNameRow && !isSectionNameRow){
// mark even rows
if(++idx % 2){
row.classList.add("odd");
Expand All @@ -221,7 +226,17 @@ function applySearch(table, search, autoExpand){
&& !row.classList.contains("row-collapsed"))
row.click();
}else{
if(heads && heads.length > 0){
if(isExtensionNameRow){
// keep the column header with no highlight, but start hidden
lastExtensionHeader = row;
lastConfigRootHeader = null;
lastSectionHeader = null;
row.style.display = "none";
} else if(isConfigRootNameRow){
lastConfigRootHeader = row;
lastSectionHeader = null;
row.style.display = "none";
} else if(isSectionNameRow){
// keep the column header with no highlight, but start hidden
lastSectionHeader = row;
row.style.display = "none";
Expand All @@ -231,6 +246,16 @@ function applySearch(table, search, autoExpand){
if(autoExpand && row.classList.contains("row-collapsed"))
row.click();
highlight(row, search);
if(lastExtensionHeader){
lastExtensionHeader.style.removeProperty("display");
// avoid showing it more than once
lastExtensionHeader = null;
}
if(lastConfigRootHeader){
lastConfigRootHeader.style.removeProperty("display");
// avoid showing it more than once
lastConfigRootHeader = null;
}
if(lastSectionHeader){
lastSectionHeader.style.removeProperty("display");
// avoid showing it more than once
Expand Down

0 comments on commit 864e22f

Please sign in to comment.