Skip to content

Commit

Permalink
Fix search
Browse files Browse the repository at this point in the history
  • Loading branch information
rugk committed Jan 21, 2019
1 parent 3dd6396 commit d22cfe4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions static/scripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function contains(a,m){

//on search
document.getElementById("nav-search").addEventListener("keyup", function(event) {
var search = this.value;
var search = this.value.toUpperCase();

if (!search) {
//no search, show all results
Expand Down Expand Up @@ -49,33 +49,33 @@ document.getElementById("nav-search").addEventListener("keyup", function(event)
elem.parentNode.style.display = "block";
});
//hide parents without children
document.querySelectorAll("nav > ul > li").forEach(function(parent){
document.querySelectorAll("nav > ul > li").forEach(function(parent) {
var countSearchA = 0;
parent.querySelectorAll("a").forEach((elem) >= {
parent.querySelectorAll("a").forEach(function(elem) {
if (contains(elem, search)) {
countSearchA++;
}
}
});

var countUl = 0;
parent.querySelectorAll("ul").forEach((elem) >= {
if (contains(elem, search)) {
var countUlVisible = 0;
parent.querySelectorAll("ul").forEach(function(ulP) {
// count all elements that match the search
if (contains(ulP, search)) {
countUl++;
}
}

var countUlVisible = 0;
parent.querySelectorAll("ul").forEach((ulP) >= {

// count all visible elements
var children = ulP.children
for (i=0; i<children.length; i++) {
var elem = children[i];
if (elem.style.display != "none") {
countUlVisible++;
}
}
}
});

if(countSearchA == 0 && countUl === 0){
if (countSearchA == 0 && countUl === 0){
//has no child at all and does not contain text
parent.style.display = "none";
} else if(countSearchA == 0 && countUlVisible == 0){
Expand Down

0 comments on commit d22cfe4

Please sign in to comment.