//REMOVES UNECESSARY MENU ITEMS /* baseMenuItem refers to the top menu item of the selected sub menu item. Can possibly be the top menu item when it is selected */ var baseMenuItem = document.getElementsByClassName('current_page_ancestor')[0]; //Runs when there is a parent(s) (or ancestor here) of the current selected menu item if (baseMenuItem !== undefined){ recursiveMenuParser(baseMenuItem); } /* Else runs the finalCase to begin with, as then the selected menu item must be on the top level of the menu. */ else { finalCase(document.getElementsByClassName('current_page_item')[0]); } /* Parses the menu and deletes the children of menu items not within the branch of the selected menu item */ function recursiveMenuParser (list) { //Active Menus holds the children of the current menu item to be parsed var activeMenus = list.getElementsByClassName('children')[0].children; //Temp holds the next parent menu item whos children have to be parsed var temp = null; //Iterates through each child for (var i = 0; i < activeMenus.length; i++){ //Runs when the current menu item is hit if (activeMenus[i].className.includes('current_page_item')){ finalCase(activeMenus[i]); } //Sets value equal to temp if it is an ancestor of the active page else if (activeMenus[i].className.includes('current_page_ancestor')){ temp = activeMenus[i]; } //If the current child is not an ancestor and has children, makes children invisible else { if (activeMenus[i].getElementsByClassName('children')[0] !== undefined){ var deleteMenu = activeMenus[i].getElementsByClassName('children')[0]; deleteMenu.style.display = "none"; } } } //If the menu has not reached the depth of the current menu item, runs function recursivly again if (temp !== null) { return recursiveMenuParser(temp); } return 0; } //This makes one level of menu visible below the current selected menu item function finalCase (list) { var activeMenuItem = list.getElementsByClassName('children')[0]; if (activeMenuItem !== undefined) { //Sets the children of the active menu to activeMenuItemChildren var activeMenuItemChildren = activeMenuItem.children; //Iterates and makes the children of the children of the selected menu item invisible for (var i = 0; i < activeMenuItemChildren.length; i++){ if (activeMenuItemChildren[i].getElementsByClassName('children')[0] !== undefined){ var deleteMenu = activeMenuItemChildren[i].getElementsByClassName('children')[0]; deleteMenu.style.display = "none"; } } } }