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 e39bbc2
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions static/scripts/search.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@

var searchAttr = 'data-search-mode';
function contains(a,m){
if (m.length < 3) {
return false;
}

return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
return (a.textContent || a.innerText || "").toUpperCase().includes(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 +45,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 e39bbc2

Please sign in to comment.