-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
193 lines (139 loc) · 4.65 KB
/
index.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
// **********************Search****************************************
document.addEventListener("click", (evt) => {
const flyoutEl = document.getElementById("search");
let targetEl = evt.target; // clicked element
do {
if (targetEl == flyoutEl) {
// This is a click inside, does nothing, just return.
toggleSearchDivs();
return;
}
// Go up the DOM
targetEl = targetEl.parentNode;
} while (targetEl);
// This is a click outside.
collapseSearchDivs();
});
function toggleSearchDivs() {
let search = document.getElementById("search");
let search_bar = document.getElementById("search-bar");
let right_div = document.getElementById("right");
let middle_div = document.getElementById("middle");
search.style.width = "100%";
search_bar.style.width = "100%";
// search_bar.style.position="absolute";
right_div.style.width = "100%";
middle_div.style.width = "0%";
}
function collapseSearchDivs() {
let search = document.getElementById("search");
let search_bar = document.getElementById("search-bar");
let right_div = document.getElementById("right");
let middle_div = document.getElementById("middle");
search.style.width = "";
search_bar.style.width = "";
right_div.style.width = "";
middle_div.style.width = "";
search_bar.style.position="";
document.getElementById("search-suggestion").innerHTML=null;
}
// **********************Search****************************************
// **********************Signin****************************************
let signupDatafromLs=JSON.parse(localStorage.getItem("signup-data"))||[]
let nameforshow = JSON.parse(localStorage.getItem("name"))||""
let signintext=document.querySelector("#show-login")
if(nameforshow.length>0){
signintext.innerHTML= `Welcome, ${nameforshow}`
}
else {
signintext.innerHTML= `Welcome, Sign In`
}
let login = document.getElementById("show-login");
login.addEventListener("click",(e)=>{
e.preventDefault()
})
document.querySelector("#show-login").addEventListener("click",function(){
document.querySelector(".popup").classList.add("active");
})
document.querySelector(".popup .close-btn").addEventListener("click",function(){
document.querySelector(".popup").classList.remove("active")
})
let email = document.querySelector("#email")
let password = document.querySelector("#password")
let submit = document.querySelector("#signin")
submit.addEventListener("click",submitfunc)
function submitfunc(){
let obj = {
email:email.value,
password:password.value
}
loginfunc(obj)
}
function loginfunc(obj){
let emailflag =false;
let passwordflag = false;
for(let data of signupDatafromLs){
if(obj.email == data.email){
emailflag =true;
if(obj.password == data.password){
alert("Login Successful")
let name = data.full_name
localStorage.setItem("name",JSON.stringify(name))
window.location.reload()
passwordflag= true;
}
}
}// loop
if(obj.email =="" || obj.password ==""){
alert("All Field must be filled out")
}
else if(emailflag == false){
alert("Invalid Credential")
}
if(emailflag == true && passwordflag == false){
alert("Wrong Password")
}
}//function
function gotocreateaccount(){
window.location.href="./createaccount.html"
}
// **********************Signin****************************************
// **********************Search****************************************
let search = document.getElementById("search-bar");
let obj={};
fetch("./men.json")
.then(res=>res.json())
.then(data=>{
console.log(data);
obj=data;
});
//selected value in search result--start
search.addEventListener("input", (e)=>{
let searchResult=obj.filter((item,index)=>{
console.log((item.description).includes(e.target.value));
if((item.description).toLowerCase().includes(e.target.value.toLowerCase())){
return true
}
})
searchResult=searchResult.map((data)=>{
return "<li class='suggestion-list' data-style="+data.style+">"+data.description+"</li>";
})
document.getElementById("search-suggestion").innerHTML=null;
document.getElementById("search-suggestion").innerHTML=searchResult.join(" ");
document.querySelector(".suggestion-list").addEventListener("click",(e)=>{
// console.log(e.target.dataset.style);
let searchResult=obj.filter((item,index)=>{
if(item.style==e.target.dataset.style){
return true
}
})
if(searchResult[0].category=="Men"){
window.location.href="./men.html?style="+e.target.dataset.style;
}
if(searchResult[0].category=="Women"){
window.location.href="./women.html?style="+e.target.dataset.style;
}
});
})
//selected value in search result--end
// **********************Search****************************************