-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
125 lines (95 loc) · 3.42 KB
/
script.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
// Toggle class active hamburger menu
const navbarNav = document.querySelector('.navbar-nav');
const menu = document.querySelector('#hamburger-menu');
// ketika hamburger menu diklik
menu.addEventListener('click', () => {
navbarNav.classList.toggle('active');
});
// Toggle class active search form
const searchForm = document.querySelector('.search-form');
const searchBox = document.querySelector('#search-box');
const searchBtn = document.querySelector('#search-btn');
searchBtn.addEventListener('click', (e) => {
searchForm.classList.toggle('active');
searchBox.focus();
e.preventDefault();
});
// Toggle class active shopping cart
const shoppingCartBtn = document.querySelectorAll("#shopping-cart-btn");
const shoppingCart = document.querySelector(".shopping-cart");
// ketika icon shopping cart diklik
shoppingCartBtn.forEach((btn) => {
btn.addEventListener('click', (e) => {
shoppingCart.classList.toggle('active');
e.preventDefault();
});
});
// var icon close
const closeIcon = document.querySelectorAll(".close-icon");
// klik tombol close diklik
const detailModal1 = document.getElementById("detail-modal-chino-kafuu");
const detailModal2 = document.getElementById("detail-modal-chiya-ujimatsu");
const detailModal3 = document.getElementById("detail-modal-cocoa-hoto");
const detailModal4 = document.getElementById("detail-modal-midori-aoyama");
closeIcon.forEach((close) => {
close.addEventListener('click', (e) => {
detailModal1.style.display = 'none';
detailModal2.style.display = 'none';
detailModal3.style.display = 'none';
detailModal4.style.display = 'none';
e.preventDefault();
});
});
// ketika diklik selain modal box
window.onclick = (e) => {
if (e.target === detailModal1) {
detailModal1.style.display = "none";
} else if (e.target === detailModal2) {
detailModal2.style.display = "none";
} else if (e.target === detailModal3) {
detailModal3.style.display = "none";
} else if (e.target === detailModal4) {
detailModal4.style.display = "none";
}
}
// ketika add to cart diklik
const addToCart = document.querySelectorAll('#add-to-cart');
addToCart.forEach((btn) => {
btn.addEventListener('click', () => {
alert('Fitur masih belum jalan😅');
});
});
// ketika search icon diklik
function searchIconAlert() {
alert("Fitur dalam penggerjaan! sabar ygy😁");
}
// ketika btn kirim pesan di submit
function submitAlert() {
alert("Jangan di spam ya!💀");
}
// ketika btn checkout di submit
// function checkoutAlert() {
// alert("Fitur payment gateway, coming soon!💳");
// }
// klik diluar elemen
document.addEventListener('click', (e) => {
if (!menu.contains(e.target) && !navbarNav.contains(e.target)) {
navbarNav.classList.remove('active');
}
if (!searchBtn.contains(e.target) && !searchForm.contains(e.target)) {
searchForm.classList.remove('active');
}
// looping utk cart icon
let isOutsideShoppingCartBtns = true;
shoppingCartBtn.forEach((btn) => {
if (btn.contains(e.target) || shoppingCart.contains(e.target)) {
isOutsideShoppingCartBtns = false;
}
});
if (isOutsideShoppingCartBtns) {
shoppingCart.classList.remove("active");
}
// if (!shoppingCartBtn.contains(e.target) && !shoppingCart.contains(e.target)){
// shoppingCart.classList.remove("active");
// }
});