From 46ee986cb06a2b1a45a9b34a362a6339bdfd0467 Mon Sep 17 00:00:00 2001 From: JingZhang Chen Date: Thu, 18 Jan 2024 01:15:47 +0800 Subject: [PATCH 1/3] remove group elements not in the selection --- .../javascripts/paradox-material-theme.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/theme/src/main/assets/assets/javascripts/paradox-material-theme.js b/theme/src/main/assets/assets/javascripts/paradox-material-theme.js index a21561a..0b15218 100644 --- a/theme/src/main/assets/assets/javascripts/paradox-material-theme.js +++ b/theme/src/main/assets/assets/javascripts/paradox-material-theme.js @@ -217,6 +217,26 @@ function initParadoxMaterialTheme() { dl.parentNode.appendChild(contentContainer) } }) -} + + // index toc + document.querySelectorAll('.toc').forEach(tocRoot => { + + function findHeaderElements(element) { + var headerElements = element.getElementsByClassName('header'); + for (var i = 0; i < headerElements.length; i++) { + // TODO can we read $page.group on here? + if (headerElements[i].classList.contains('group-java')) { + console.log(headerElements[i].textContent); + headerElements[i].parentNode.remove(); + } + } + var childElements = element.children; + for (var j = 0; j < childElements.length; j++) { + findHeaderElements(childElements[j]); + } + } + + findHeaderElements(tocRoot); + }) initParadoxMaterialTheme() From ca98cf490fbbb6609fbfc4af5786c1a4d3bfd1c4 Mon Sep 17 00:00:00 2001 From: JingZhang Chen Date: Wed, 24 Jan 2024 10:29:33 +0800 Subject: [PATCH 2/3] using jQuery hide not the current group ele --- .../main/assets/assets/javascripts/groups.js | 35 +++++++++++++++++++ .../javascripts/paradox-material-theme.js | 22 +----------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/theme/src/main/assets/assets/javascripts/groups.js b/theme/src/main/assets/assets/javascripts/groups.js index cf812be..fb072e6 100644 --- a/theme/src/main/assets/assets/javascripts/groups.js +++ b/theme/src/main/assets/assets/javascripts/groups.js @@ -148,6 +148,41 @@ $(function() { }); }); + // Index Page toc + $(".toc").each(function() { + var tocRoot = $(this); + function findHeaderElements(element) { + var headerElements = element.find(".header"); + headerElements.each(function() { + var headerElement = $(this); + // only work with the header link + if (!headerElement.is("a")) { + return false; + } + // if header hiding by group switch, hide they li parent + // otherwise display there li parent + if (headerElement.css("display") === "none" ) { + var parentLi = headerElement.closest('li'); + if (parentLi) { + parentLi.hide(); + } + } else { + var parentLi = headerElement.closest('li'); + if (parentLi) { + parentLi.show(); + } + } + }); + // just in case there is a nested header + element.children().each(function() { + var childElement = $(this); + findHeaderElements(childElement); + }); + } + + findHeaderElements(tocRoot); + }) + groupChangeListeners.forEach(listener => listener(group, supergroup, catalog)); } diff --git a/theme/src/main/assets/assets/javascripts/paradox-material-theme.js b/theme/src/main/assets/assets/javascripts/paradox-material-theme.js index 0b15218..a21561a 100644 --- a/theme/src/main/assets/assets/javascripts/paradox-material-theme.js +++ b/theme/src/main/assets/assets/javascripts/paradox-material-theme.js @@ -217,26 +217,6 @@ function initParadoxMaterialTheme() { dl.parentNode.appendChild(contentContainer) } }) - - // index toc - document.querySelectorAll('.toc').forEach(tocRoot => { - - function findHeaderElements(element) { - var headerElements = element.getElementsByClassName('header'); - for (var i = 0; i < headerElements.length; i++) { - // TODO can we read $page.group on here? - if (headerElements[i].classList.contains('group-java')) { - console.log(headerElements[i].textContent); - headerElements[i].parentNode.remove(); - } - } - var childElements = element.children; - for (var j = 0; j < childElements.length; j++) { - findHeaderElements(childElements[j]); - } - } - - findHeaderElements(tocRoot); - }) +} initParadoxMaterialTheme() From 145a074911edb2a92639080f4e949616ea47ae50 Mon Sep 17 00:00:00 2001 From: JingZhang Chen Date: Wed, 24 Jan 2024 11:05:35 +0800 Subject: [PATCH 3/3] filter before foreach --- theme/src/main/assets/assets/javascripts/groups.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/theme/src/main/assets/assets/javascripts/groups.js b/theme/src/main/assets/assets/javascripts/groups.js index fb072e6..65614b5 100644 --- a/theme/src/main/assets/assets/javascripts/groups.js +++ b/theme/src/main/assets/assets/javascripts/groups.js @@ -152,13 +152,9 @@ $(function() { $(".toc").each(function() { var tocRoot = $(this); function findHeaderElements(element) { - var headerElements = element.find(".header"); + var headerElements = element.find(".header").filter("a"); headerElements.each(function() { var headerElement = $(this); - // only work with the header link - if (!headerElement.is("a")) { - return false; - } // if header hiding by group switch, hide they li parent // otherwise display there li parent if (headerElement.css("display") === "none" ) { @@ -181,7 +177,7 @@ $(function() { } findHeaderElements(tocRoot); - }) + }) groupChangeListeners.forEach(listener => listener(group, supergroup, catalog)); }