mirror of
https://github.com/FranP-code/API-and-CRUD-for-Ecommerce-with-Node.js-FRONTEND.git
synced 2025-10-12 23:52:33 +00:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
const navbarLogica = async (activeCategory, globalProductos, enviarProductoAlCheckout, checkout, totalLogica, stylesLogica, definirProductos) => {
|
|
|
|
const childrenNavbar = document.querySelectorAll('.exposicion-de-productos nav ul li.button')
|
|
|
|
childrenNavbar.forEach(children => {
|
|
|
|
children.addEventListener('click', () => {
|
|
|
|
globalProductos = []
|
|
|
|
activeCategory = children.innerText
|
|
makeThisCategoryActive()
|
|
definirProductos(globalProductos, activeCategory, enviarProductoAlCheckout, checkout, totalLogica, stylesLogica)
|
|
})
|
|
})
|
|
|
|
const makeThisCategoryActive = () => {
|
|
|
|
childrenNavbar.forEach(children => {
|
|
|
|
if (!children.children[0]) {
|
|
|
|
if (activeCategory === children.innerText) {
|
|
|
|
children.classList.add('active')
|
|
}
|
|
|
|
else if (children.classList.contains('active')) {
|
|
|
|
children.classList.remove('active')
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
makeThisCategoryActive()
|
|
}
|
|
|
|
export default navbarLogica |