-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
134 lines (110 loc) · 3.72 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
//container -1 sliding component
var slider = document.querySelector(".container-1");
var slides = document.querySelectorAll(".slide1");
slider.style.overflow = "hidden";
slides.forEach(function (s, i) {
console.log(i);
s.style.transform = `translateX(${100 * i}%)`;
});
console.log(slides);
var curSlide = 0;
var maxSlide = slides.length - 1;
var btnRight = document.querySelector(".btn-right");
btnRight.addEventListener("click", function () {
if (curSlide == maxSlide) {
curSlide = 0;
} else {
curSlide++;
}
slides.forEach(function (s, i) {
console.log(i);
s.style.transform = `translateX(${100 * (i - curSlide)}%)`;
});
});
var btnLeft = document.querySelector(".btn-left");
btnLeft.addEventListener("click", function () {
if (curSlide == 0) {
curSlide = maxSlide;
} else {
curSlide--;
}
slides.forEach(function (s, i) {
console.log(i);
s.style.transform = `translateX(${100 * (i - curSlide)}%)`;
});
});
document.querySelector("#buttons").addEventListener("click", signinFunc);
function signinFunc() {
document.querySelector(".signin-modal").style.display = "flex";
}
document.querySelector(".closein").addEventListener("click", closeinFunc);
function closeinFunc() {
document.querySelector(".signin-modal").style.display = "none";
}
document.querySelector("#button").addEventListener("click", signupFunc);
function signupFunc() {
document.querySelector(".bg-modal").style.display = "flex";
}
document.querySelector(".close").addEventListener("click", closeFunc);
function closeFunc() {
document.querySelector(".bg-modal").style.display = "none";
}
document.querySelector("#signUp-form").addEventListener("submit", function () {
event.preventDefault();
var userData = JSON.parse(localStorage.getItem("userCreds")) || [];
var userObj = {
firstName: document.querySelector("#first").value,
lastName: document.querySelector("#last").value,
email: document.querySelector("#email").value,
mobile: document.querySelector("#mobile").value,
password: document.querySelector("#pass").value,
birthDate: document.querySelector("#birth").value,
};
userData.push(userObj);
localStorage.setItem("userCreds", JSON.stringify(userData));
window.location.href = "afterSign.html";
alert("Login Successful!");
});
document.querySelector("#signIn-form").addEventListener("submit", function () {
event.preventDefault();
var regdUsers = JSON.parse(localStorage.getItem("userCreds"));
var enteredEmail = document.querySelector("#userName").value;
var enteredPass = document.querySelector("#password").value;
for (var i = 0; i < regdUsers.length; i++) {
if (
regdUsers[i].email == enteredEmail &&
regdUsers[i].password == enteredPass
) {
alert("Login Succesfull!");
window.location.href = "afterSign.html";
break;
} else {
alert("Login Failure!");
window.location.href = "index.html";
break;
}
}
});
function onloadcartnumber() {
var productnumber = localStorage.getItem("cartNumber");
if (productnumber) {
document.querySelector(" #cartno").textContent = productnumber;
}
}
function cartNumber() {
var productnumber = localStorage.getItem("cartNumber") || [];
productnumber = parseInt(productnumber);
if (productnumber) {
localStorage.setItem("cartNumber", productnumber + 1);
document.querySelector("#cartno").textContent = productnumber + 1;
} else {
localStorage.setItem("cartNumber", 0);
document.querySelector("#cartno").innerText = 0;
}
}
onloadcartnumber();
cartNumber();
document.querySelector("#submitt").addEventListener("click", function () {
document.querySelector(".bg-modal").style.display = "flex";
document.querySelector(".signin-modal").style.display = "none";
});