-
Notifications
You must be signed in to change notification settings - Fork 2
/
shop4.js
292 lines (206 loc) · 7.96 KB
/
shop4.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
var robinData = [
{
image_url: "https://static.thcdn.com/images/xsmall/original//productimg/original/12747907-1514871998779558.jpg",
name: "DERMAdoctor KP Duty Body Scrub (Various Sizes)",
box: "DERMAdoctor Gift",
price: "32",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/11287210-1584882191614736.jpg",
name: "DERMAdoctor Kakadu C Brightening Daily Cleanser 7.1 oz Tube",
box: "DERMAdoctor Gift",
price: "38.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/11287222-1874871998236897.jpg",
name: "DERMAdoctor Total Nonscents Ultra Gentle Brightening Antiperspirant",
box: "DERMAdoctor Gift",
price: "30.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/11718351-1104866363990105.jpg",
name: "DERMAdoctor Ain't Misbehavin' Medicated Acne Cleanser 7.1 oz",
box: "DERMAdoctor Gift",
price: "32.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/11712346-3214896398286015.jpg",
name: "DERMAdoctor Picture Porefect Pore Minimizer",
box: "DERMAdoctor Gift",
price: "42.00",
},
{
image_url: "https://static.thcdn.com/images/xsmall/webp//productimg/original/11287208-2084871998090722.jpg",
name: "DERMAdoctor Kakadu C 20% Vitamin C Serum with Ferulic Acid and Vitamin E",
box: "DERMAdoctor Gift",
price: "95.00",
},
{
image_url: "https://static.thcdn.com/images/xsmall/webp//productimg/original/11412607-8954864280050704.jpg",
name: "DERMAdoctor Kakadu C Vitamin C Brightening Kit (Worth $129.00)",
box: "DERMAdoctor Gift",
price: "89.00",
},
{
image_url: "https://static.thcdn.com/images/xsmall/webp//productimg/original/11412608-1034872055783974.jpg",
name: "DERMAdoctor Med e Tate Antiperspirant Wipes (30 Pack)",
box: "DERMAdoctor Gift",
price: "48.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/12187514-2304815573253458.jpg",
name: "Elemis Pro-Collagen Rose Facial Oil 15ml",
box: "DERMAdoctor Gift",
price: "79.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/12698709-1824880131032636.jpg",
name: "DERMAdoctor KP Duty Dermatologist for Dry, Rough, Bumpy Skin 8 oz",
box: "DERMAdoctor Gift",
price: "38.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/11290613-8274866327106473.jpg",
name: "DERMAdoctor DD Cream Dermatologically Spectrum SPF 30",
box: "DERMAdoctor Gift",
price: "40.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/12624607-9824815576214422.jpg",
name: "Elemis Superfood AHA Glow Cleansing 90g",
box: "DERMAdoctor Gift",
price: "38.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/10451465-6984815568966494.jpg",
name: "Elemis Frangipani Monoi Body Oil 100ml",
box: "DERMAdoctor Gift",
price: "56.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/10362741-1744840455658752.jpg",
name: "Elemis Dynamic Resurfacing Facial Wash",
box: "DERMAdoctor Gift",
price: "49.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/12543334-1854815575687697.jpg",
name: "Elemis Ultra Smart Enviro-Adapt Day50ml",
box: "$32 Elemis Gift",
price: "295.00",
},
{
image_url: "https://static.thcdn.com/images/large/webp//productimg/1600/1600/10621773-4934891242155358.jpg",
name: "Elemis Pro-Collagen Eye Treatment (15ml)",
box: "$32 Elemis Gift",
price: "68.00",
},
];
// var cartArray = JSON.parse(localStorage.getItem("cartItems")) || [];
// var wishArray = JSON.parse(localStorage.getItem("wishItems")) || [];
reLoadM(robinData);
function reLoadM(robinData){
// DATA
displayDatas(robinData);
function displayDatas(robinData){
document.querySelector("#container").textContent="";
robinData.map(function (data) {
var div = document.createElement("div")
document.querySelector("#container").append(div)
// inside div creating image and image_url
var image = document.createElement("img");
image.setAttribute("src", data.image_url);
div.append(image);
var name = document.createElement("p");
name.style.height = "35px"
name.textContent = data.name;
name.style.marginTop = "3%"
div.append(name);
var box = document.createElement("div")
box.textContent = data.box
box.setAttribute("id", "boxer")
div.append(box)
var p2 = document.createElement("p")
p2.textContent = `$${data.price}`;
p2.style.marginTop = "3%"
p2.style.fontSize = "24px"
p2.style.fontWeight = "bold"
div.append(p2)
var btn1 = document.createElement("button")
btn1.setAttribute("id", "btnwish")
btn1.textContent = "Wish"
btn1.style.display = "block"
btn1.addEventListener("click", function () {
wishlistAdd(data);
})
div.append(btn1)
var btn2 = document.createElement("button")
btn2.setAttribute("id", "btnbuy");
btn2.textContent = "QUICK BUY"
btn2.addEventListener("click", function () {
cartAdd(data);
})
div.append(btn2);
})
}
var cartThings = JSON.parse(localStorage.getItem("cartthings")) || [];
var cartArray = JSON.parse(localStorage.getItem("quickbuy1")) || [];
function wishlistAdd(data) {
cartArray.push(data);
cartThings.push(data);
localStorage.setItem("quickbuy1", JSON.stringify(cartArray));
localStorage.setItem("cartthings", JSON.stringify(cartThings));
alert("Item Added");
reLoadM(robinData);
}
function cartAdd(data) {
cartThings.push(data);
localStorage.setItem("cartthings", JSON.stringify(cartThings));
alert("added to cart");
reLoadM(robinData);
}
// console.log(cartArray);
// console.log(cartArray);
// Read More Drop Down Function
// ==============================================================================================================================================
var cartLength =JSON.parse(localStorage.getItem("cartthings"))
document.querySelector("#cardAval").innerHTML=`There are currently ${cartLength.length} items in your cart.`;
document.querySelector("#cartLen").innerHTML=`${cartLength.length}`;
}
function navSlideOut(){
document.querySelector("#nav-link").style.left="-16px"
}
function navSlideIn(){
document.querySelector("#nav-link").style.left="-2000px"
}
function myFunction() {
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if (dots.style.display === "none") {
dots.style.display = "inline";
btnText.innerHTML = "Read more";
moreText.style.display = "none";
} else {
dots.style.display = "none";
btnText.innerHTML = "Read less";
moreText.style.display = "inline";
}
}
function Tsort(){
var valT=document.querySelector("#sortT").value
console.log(valT)
if(valT==""){
reLoadM(robinData);
}else if(valT=="high"){
robinData.sort(function(a,b){
return (Number(b.price)-Number(a.price))
})
reLoadM(robinData);
}else{
robinData.sort(function(a,b){
return (Number(a.price)-Number(b.price))
})
reLoadM(robinData);
}
}