-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.html
246 lines (184 loc) · 7.09 KB
/
search.html
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FAB BAG: Monthly Makeup & Beauty Subscription for Women</title>
<script
src="https://kit.fontawesome.com/24c494a6b6.js"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="./search.css">
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-Xe+8cL9oJa6tN/veChSP7q+mnSPaj5Bcu9mPX5F5xIGE0DVittaqT5lorf0EI7Vk" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-ODmDIVzN+pFdexxHEHFBQH3/9/vQ9uori45z4JjnFsRydbmQbmL5t1tQ0culUzyK" crossorigin="anonymous"></script>
<link rel="stylesheet" href="styles/navbar.css">
<link rel="shortcut icon" href="//cdn.shopify.com/s/files/1/0052/7551/6995/files/LOGO_32x32.png?v=1548735766" type="image/png">
</head>
<body>
<div id="navbar">
</div>
<!-- Button trigger modal -->
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<div id="container">
<div id="icon_div"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"> <span id="delete_icon"><i class="fa-solid fa-xmark"></i></span></button>
</div>
</div>
<div id="box">
<form action="">
<h5 id="grey">WHAT ARE YOU LOOKING FOR ?</h5>
<input id="search_box" autocomplete="off" placeholder="search product" type="text"> <span id="search_icon"><i class="fa-solid fa-magnifying-glass"></i></span>
</form>
<div id="results">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
let Navbar=document.getElementById("navbar")
let minibox= document.getElementById("search_box")
minibox.onclick=function() {
minibox.style.borderWidth="1px"
minibox.style.borderColor="black"
}
// import navbar from "./components/navbar.js"
// Navbar.innerHTML=navbar()
document.getElementById('search_icon').addEventListener('click',searchfun)
function searchfun(){
document.getElementById("results").innerHTML=null;
document.querySelector(".modal-body").style.display="block"
// console.log('open')
}
document.getElementById("delete_icon").onclick=function() {
console.log("close")
// document.querySelector(".modal-body").style.transform='translateY(-300px)';
// document.querySelector(".modal-body").style.transition='0.5s';
document.querySelector(".modal-body").style.display='none'
window.location.href = "./index.html"
}
let arrData= [
{
id: 1,
name: "SUGAR Born To Wing Gel Eyeliner - 03 Brown Sugar (Walnut Brown)",
image:
"https://cdn.shopify.com/s/files/1/0052/7551/6995/products/8904320702793A.jpg?v=1574400002",
Price: "599.00 ",
},
{
id: 2,
name: "SUGAR Uptown Curl Lengthening Mini Mascara - 01 Black Beauty (Black) + SUGAR Wingman Waterproof Microliner - 01 I'll Be Black (Black)",
image:
"https://cdn.shopify.com/s/files/1/0052/7551/6995/products/SUGAR-Uptown-Curl-mini-mascara-_-SUGAR-Wingman-Waterproof-Microliner-01-I_ll-Be-Black-_Black_b4408b1d-058e-423d-a933-18d206385730.png?v=1592831244",
Price: "799.00 ",
},
{
id: 3,
name: "SUGAR Aquaholic Priming Moisturizer",
image:
"https://cdn.shopify.com/s/files/1/0052/7551/6995/products/Aquaholic-Priming-Moisturizer-_-Open-Prdocut_Pigment.jpg?v=1586794134",
Price: "699.00 ",
},
{
id: 3,
name: "SUGAR Aquaholic Priming Moisturizer",
image:
"https://cdn.shopify.com/s/files/1/0052/7551/6995/products/Aquaholic-Priming-Moisturizer-_-Open-Prdocut_Pigment.jpg?v=1586794134",
Price: "699.00 ",
},
{
id: 4,
name: "SUGAR Bling Leader Illuminating Moisturizer",
image:
"https://cdn.shopify.com/s/files/1/0052/7551/6995/products/WBG_01-Gold-Diggin__02-2_36f47c3b-bf42-4ffd-aa7f-7a3971e3ff6e.jpg?v=1579677440",
Price: "699.00 ",
},
{
id: 5,
name: "https://cdn.shopify.com/s/files/1/0052/7551/6995/products/WBG_01-Gold-Diggin__02-2_36f47c3b-bf42-4ffd-aa7f-7a3971e3ff6e.jpg?v=1579677440",
image:
"https://cdn.shopify.com/s/files/1/0052/7551/6995/products/Powder-Play-_translucent.png?v=1579676442",
Price: "599.00",
},
{
id: 6,
name: "SUGAR Powder Play Banana Compact",
image:
"https://cdn.shopify.com/s/files/1/0052/7551/6995/products/Powder-Play-_Banana_-Open-Product-_-swatcht.png?v=1579756892",
Price: "599.00",
},
{
id: 7,
name: "SUGAR The Most Eligiblur Smoothing Primer",
image:
"https://cdn.shopify.com/s/files/1/0052/7551/6995/products/9D5A7539.jpg?v=1586794313",
Price: "799.00",
},
]
//let query=document.getElementById("search_box");
//query.addEventListener('click',inputfun)
// function inputfun(){
// console.log("ffdfd")
// }
document.getElementById("search_box").oninput=function() {
let query=document.getElementById("search_box").value;
if(query==="sugar") {
let url=`https://rizofabbag.herokuapp.com/fabData?q=${query}`
getData(url)
document.getElementById("search_box").style.border="none"
}
else {
console.log("not working")
}
}
async function getData(url) {
let res=await fetch(url);
let data= await res.json();
appendfun(data)
}
function appendfun(products) {
document.getElementById("results").innerHTML=null;
products.forEach((el,i)=>{
let img=document.createElement("img")
img.style.width="50px"
img.style.height="70px"
img.src=el.image;
img.style.cursor = "pointer"
let name=document.createElement("p")
name.innerText=el.name;
name.style.cursor = "pointer"
name.setAttribute("class","effect")
name.style.fontFamily="sans-sherif"
let price=document.createElement("p")
price.innerText=el.Price;
price.style.cursor = "pointer"
price.setAttribute("class","effect")
let box=document.createElement("div")
box.style.display="flex"
box.style.width="300px"
box.style.gap="15px"
box.style.cursor = "pointer"
box.addEventListener("click",function(){
sendData(el)
})
box.append(img,name,price)
setTimeout(()=>{
document.getElementById("results").append(box)
},500)
})
}
function sendData(product) {
localStorage.setItem("Product",JSON.stringify(product))
window.location.href="detailed.html"
}
</script>