-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
184 lines (149 loc) · 5.11 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
const menuEmail = document.querySelector('.navbar-email');
const desktopMenu = document.querySelector('.desktop-menu');
const menuHambIcon = document.querySelector('.menu-hamb');
const productDetailCloseIcon = document.querySelector('.product-detail-close');
const mobileMenu = document.querySelector('.mobile-menu')
const cartIcon = document.querySelector('.navbar-shopping-cart')
const shoppingCartContainer = document.querySelector('#shoppingCartContainer');
const productDetailContainer = document.querySelector('#productDetail')
const cardsContainer = document.querySelector('.cards-container')
menuEmail.addEventListener('click', toggleDesktopMenu);
menuHambIcon.addEventListener('click', toggleMobileMenu);
cartIcon.addEventListener('click', toggleCartAside);
productDetailCloseIcon.addEventListener('click', closeProductDetailAside );
function toggleDesktopMenu() {
const isAsideClosed = shoppingCartContainer.classList.contains('inactive');
if(!isAsideClosed) {
shoppingCartContainer.classList.add('inactive');
}
desktopMenu.classList.toggle('inactive');
}
function toggleMobileMenu() {
const isAsideClosed = shoppingCartContainer.classList.contains('inactive');
if(!isAsideClosed) {
shoppingCartContainer.classList.add('inactive');
}
closeProductDetailAside();
mobileMenu.classList.toggle('inactive');
}
function toggleCartAside() {
const isMobileMenuClosed = mobileMenu.classList.contains('inactive')
//shoppingCartContainer.classList.toggle('inactive');
if(!isMobileMenuClosed) {
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 : 'Plant Pot',
price: 135,
image: "./assets/products/1graypot_purpleplate.jpg"
});
productList.push({
name : 'White Ceramic Plant Pot',
price: 145,
image: "./assets/products/2whiteJar.jpg"
});
productList.push({
name : 'Thre Ceramic Plant Pots',
price: 235,
image: "./assets/products/3whiteJarandplates.jpg"
});
productList.push({
name : 'Pink Plant Pot',
price: 138,
image: "./assets/products/11pinkpot.jpg"
});
productList.push({
name: 'Orange Plant Pot and Purple Base',
price: 120,
image: './assets/products/5orangepotandgoldenvase.jpg'
});
productList.push({
name: 'White Jar',
price: 125,
image: './assets/products/6whitejar2.jpg'
});
productList.push({
name: 'Orange Pot',
price: 133,
image: './assets/products/7orangepot.jpg'
});
productList.push({
name: 'Light Purple Vase and Jar',
price: 141,
image: './assets/products/8brown_bluejar.jpg'
});
productList.push({
name: 'Brown Classic Pot',
price: 88,
image: './assets/products/9brownpot_cactus.jpg'
});
productList.push({
name: 'Brown Classic Pot & green plate',
price: 99,
image: './assets/products/10brownpot_green.jpg'
});
productList.push({
name: 'Pink Pot and Pale Pink plate',
price: 125,
image: './assets/products/11pinkpot.jpg'
});
productList.push({
name: 'Ocean Blue Vase and Jar',
price: 135,
image: './assets/products/12.jpeg'
});
// <div class="product-card">
// <img src="./assets/products/1graypot_purpleplate.jpg" alt="gray pot" class="product-img">
// <div class="product-info">
// <div>
// <p>$135,00</p>
// <p>Plant Pot</p>
// </div>
// <figure>
// <img src="/assets/YardSale_Icons/bt_add_to_cart.svg" alt="logo cart" class>
// </figure>
// </div>
// </div>
function renderProducts(arr){
for (product of arr) {
const productCard = document.createElement('div');
productCard.classList.add('product-card');
//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');
const productInfoDiv = document.createElement('div');
const productPrice = document.createElement('p');
productPrice.innerText = '$' + product.price;
const productName = document.createElement('p');
productName.innerText = product.name;
productInfoDiv.appendChild(productPrice);
productInfoDiv.appendChild(productName);
const productInfoFigure = document.createElement('figure');
const productImgCart = document.createElement('img');
productImgCart.setAttribute('src', "/assets/YardSale_Icons/bt_add_to_cart.svg");
productInfoFigure.appendChild(productImgCart);
productInfo.appendChild(productInfoDiv);
productInfo.appendChild(productInfoFigure);
productCard.appendChild(productImg);
productCard.appendChild(productInfo);
cardsContainer.appendChild(productCard);
}
}
renderProducts(productList);