From 63386baa0d790b2df348da563d8defbf25643919 Mon Sep 17 00:00:00 2001 From: Reece Browne Date: Thu, 19 Dec 2024 12:58:57 +0000 Subject: [PATCH] Conditional logic for stacking columns --- src/main/resources/static/css/navbar.css | 8 +++ src/main/resources/static/js/navbar.js | 51 ++++++++++++++----- .../resources/templates/fragments/navbar.html | 8 +-- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/main/resources/static/css/navbar.css b/src/main/resources/static/css/navbar.css index a437f0ec..71c57398 100644 --- a/src/main/resources/static/css/navbar.css +++ b/src/main/resources/static/css/navbar.css @@ -366,3 +366,11 @@ span.icon-text::after { background-color: #0056b3; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); } + +#stacked { + gap: 1rem; +} + +#stacked > .navbar-item { + margin: 0; +} diff --git a/src/main/resources/static/js/navbar.js b/src/main/resources/static/js/navbar.js index de8509ad..97272a5b 100644 --- a/src/main/resources/static/js/navbar.js +++ b/src/main/resources/static/js/navbar.js @@ -1,18 +1,45 @@ -function removeElements() { +function toolsManager() { document.addEventListener('DOMContentLoaded', function () { - document.querySelectorAll('.navbar-item').forEach((element) => { - const dropdownItems = element.querySelectorAll('.dropdown-item'); - const items = Array.from(dropdownItems).filter((item) => !item.querySelector('hr.dropdown-divider')); + const stackedContainer = document.getElementById('stacked'); - if (items.length == 0) { - if ( - element.previousElementSibling && - element.previousElementSibling.classList.contains('navbar-item') && - element.previousElementSibling.classList.contains('nav-item-separator') - ) { - element.previousElementSibling.remove(); + if (stackedContainer) { + const convertToPDF = stackedContainer.querySelector('.navbar-item:first-child'); + const convertFromPDF = stackedContainer.querySelector('.navbar-item:nth-child(2)'); + + if (convertToPDF && convertFromPDF) { + const dropdownItemsTo = convertToPDF.querySelectorAll('.dropdown-item'); + const dropdownItemsFrom = convertFromPDF.querySelectorAll('.dropdown-item'); + + const itemsTo = Array.from(dropdownItemsTo).filter((item) => !item.querySelector('hr.dropdown-divider')); + const itemsFrom = Array.from(dropdownItemsFrom).filter((item) => !item.querySelector('hr.dropdown-divider')); + + const totalItems = itemsTo.length + itemsFrom.length; + + if (totalItems > 12) { + stackedContainer.style.flexDirection = 'row'; + stackedContainer.classList.remove('col-lg-2'); + stackedContainer.classList.add('col-lg-4'); + convertToPDF.style.flex = '1 1 50%'; + convertFromPDF.style.flex = '1 1 50%'; + } + } + } + + document.querySelectorAll('.navbar-item').forEach((element) => { + if (!element.closest('#stacked')) { + const dropdownItems = element.querySelectorAll('.dropdown-item'); + const items = Array.from(dropdownItems).filter((item) => !item.querySelector('hr.dropdown-divider')); + + if (items.length === 0) { + if ( + element.previousElementSibling && + element.previousElementSibling.classList.contains('navbar-item') && + element.previousElementSibling.classList.contains('nav-item-separator') + ) { + element.previousElementSibling.remove(); + } + element.remove(); } - element.remove(); } }); }); diff --git a/src/main/resources/templates/fragments/navbar.html b/src/main/resources/templates/fragments/navbar.html index aa69681f..d4cdebbe 100644 --- a/src/main/resources/templates/fragments/navbar.html +++ b/src/main/resources/templates/fragments/navbar.html @@ -5,7 +5,7 @@