From 6adeecac9c1f9f20161a618b722a55c2e11e84a3 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com.> Date: Mon, 20 May 2024 18:43:47 +0100 Subject: [PATCH] fix tool removal in navbar --- .../resources/static/js/languageSelection.js | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/resources/static/js/languageSelection.js b/src/main/resources/static/js/languageSelection.js index 7af113d0..55f0647e 100644 --- a/src/main/resources/static/js/languageSelection.js +++ b/src/main/resources/static/js/languageSelection.js @@ -60,23 +60,22 @@ function handleDropdownItemClick(event) { } document.addEventListener("DOMContentLoaded", function () { - document.querySelectorAll(".nav-item.dropdown").forEach((element) => { - const dropdownMenu = element.querySelector(".dropdown-menu"); - if ( - dropdownMenu.id !== "favoritesDropdown" && - dropdownMenu.children.length <= 2 && - dropdownMenu.querySelectorAll("hr.dropdown-divider").length === dropdownMenu.children.length - ) { - if ( - element.previousElementSibling && - element.previousElementSibling.classList.contains("nav-item") && - element.previousElementSibling.classList.contains("nav-item-separator") - ) { - element.previousElementSibling.remove(); - } - element.remove(); + +document.querySelectorAll(".col-lg-2.col-sm-6").forEach((element) => { + const dropdownItems = element.querySelectorAll(".dropdown-item"); + const items = Array.from(dropdownItems).filter(item => !item.querySelector("hr.dropdown-divider")); + + if (items.length <= 2) { + if ( + element.previousElementSibling && + element.previousElementSibling.classList.contains("col-lg-2") && + element.previousElementSibling.classList.contains("nav-item-separator") + ) { + element.previousElementSibling.remove(); + } + element.remove(); } - }); +}); //Sort languages by alphabet const list = Array.from(document.querySelector('.dropdown-menu[aria-labelledby="languageDropdown"]').children).filter(