From c99166754243d4de6a1259dc376c96c3ae935d5f Mon Sep 17 00:00:00 2001 From: Juan David Castro Date: Wed, 25 May 2022 10:47:21 -0500 Subject: [PATCH] final code --- main.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index c969bffc8..7ebb1bb3e 100644 --- a/main.js +++ b/main.js @@ -1,14 +1,17 @@ const menuEmail = document.querySelector('.navbar-email'); const menuHamIcon = document.querySelector('.menu'); const menuCarritoIcon = document.querySelector('.navbar-shopping-cart'); +const productDetailCloseIcon = document.querySelector('.product-detail-close') const desktopMenu = document.querySelector('.desktop-menu'); const mobileMenu = document.querySelector('.mobile-menu'); const shoppingCartContainer = document.querySelector('#shoppingCartContainer'); +const productDetailContainer = document.querySelector('#productDetail'); const cardsContainer = document.querySelector('.cards-container'); menuEmail.addEventListener('click', toggleDesktopMenu); menuHamIcon.addEventListener('click', toggleMobileMenu); menuCarritoIcon.addEventListener('click', toggleCarritoAside); +productDetailCloseIcon.addEventListener('click', closeProductDetailAside); function toggleDesktopMenu() { const isAsideClosed = shoppingCartContainer.classList.contains('inactive'); @@ -26,6 +29,8 @@ function toggleMobileMenu() { if (!isAsideClosed) { shoppingCartContainer.classList.add('inactive'); } + + closeProductDetailAside(); mobileMenu.classList.toggle('inactive'); } @@ -34,12 +39,27 @@ function toggleCarritoAside() { const isMobileMenuClosed = mobileMenu.classList.contains('inactive'); if (!isMobileMenuClosed) { - mobileMenu.classList.add('inactive'); + mobileMenu.classList.add('inactive'); + } + + const isProductDetailClosed = productDetailContainer.classList.contains('inactive'); + + if (!isProductDetailClosed) { + productDetailContainer.classList.add('inactive'); } shoppingCartContainer.classList.toggle('inactive'); } +function openProductDetailAside() { + shoppingCartContainer.classList.add('inactive'); + productDetailContainer.classList.remove('inactive'); +} + +function closeProductDetailAside() { + productDetailContainer.classList.add('inactive'); +} + const productList = []; productList.push({ name: 'Bike', @@ -65,6 +85,7 @@ function renderProducts(arr) { // product= {name, price, image} -> product.image const productImg = document.createElement('img'); productImg.setAttribute('src', product.image); + productImg.addEventListener('click', openProductDetailAside); const productInfo = document.createElement('div'); productInfo.classList.add('product-info');