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
modularizated scripts
This commit is contained in:
39
scripts/navbarLogica.js
Normal file
39
scripts/navbarLogica.js
Normal file
@@ -0,0 +1,39 @@
|
||||
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
|
||||
Reference in New Issue
Block a user