-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
106 lines (77 loc) · 2.44 KB
/
main.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
const navbar = document.getElementById('navbarphone');
const toggle = document.getElementById('toggle');
const loaderWave2 = document.querySelector(".loader");
toggle.addEventListener('click', (e) => {
navbar.classList.toggle('active');
});
const testimonials = document.querySelectorAll('.test-card');
const prev = document.querySelector('.prev')
const next = document.querySelector('.next')
let startIndex = 0
function showTestimonials(activeIndex) {
testimonials.forEach((item,index)=>{
item.style.display= "none"
})
for(let i = activeIndex;i<activeIndex+2;i++){
testimonials[i].style.display = 'block'
}
}
showTestimonials(0);
next.addEventListener('click',()=>{
if(startIndex + 2 > testimonials.length -1){
}else{
startIndex = startIndex+2
showTestimonials(startIndex)
}
})
prev.addEventListener('click',()=>{
if(startIndex - 2 < 0 ){
}else{
startIndex = startIndex-2
showTestimonials(startIndex)
}
})
const subscribeForm = document.querySelector("#subscribeForm")
subscribeForm.addEventListener("submit", async(e)=>{
e.preventDefault()
const subEmail = document.querySelector("#subEmail")
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if(emailRegex.test(subEmail.value )){
(loaderWave2.style.display = "flex"),
(document.querySelector(".btn-word").style.display = "none");
const data = {
email: subEmail.value
}
await fetch("https://mybrand-backend-1-8rxh.onrender.com/auth/subscribe",{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
}).then((res)=>{
if(!res.ok){
console.log("---->error")
}
return res.json()
}).then((data)=>{
(loaderWave2.style.display = "none"),
(document.querySelector(".btn-word").style.display = "flex");
var popup = document.getElementById("popup");
popup.textContent = "subscription added";
popup.classList.add("show");
subEmail.value = ""
setTimeout(function () {
popup.classList.remove("show");
reloadFunc();
}, 3000);
console.log(data)
}).catch((error)=>{
console.log(error)
})
}else{
subEmail.style.border = "1px solid red"
setTimeout(function () {
subEmail.style.border = "none"
}, 3000);
}
})