-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
103 lines (92 loc) · 2.47 KB
/
Copy pathmain.js
File metadata and controls
103 lines (92 loc) · 2.47 KB
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
//swiper controller
var mySwiper = new Swiper('.swiper-container', {
direction: 'horizontal',
loop: true,
speed: 500,
effect: 'slide',
autoplay: {
delay: 5000,
},
// pagination
pagination: {
el: '.swiper-pagination',
clickable: true
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
observer: true,
observeParents: true,
})
// nav bar controller
var navButton = document.getElementById('nav-btn');
var menu = document.getElementById('main-nav');
var send = document.getElementById('send');
var modal = document.getElementById('modal');
var loading = document.getElementById('loading');
var done = document.getElementById('done');
var close = document.getElementById('close');
var emailReg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var firstName = document.getElementById('first-name');
var lastName = document.getElementById('last-name');
var email = document.getElementById('email');
var phone = document.getElementById('phone');
var message = document.getElementById('message');
navButton.addEventListener('click', function() {
menu.classList.toggle('active');
});
if (send) {
send.addEventListener('click', sendEmail);
}
if (close) {
close.addEventListener('click', function() {
modal.style.display = 'none';
});
}
function sendEmail(e) {
e.preventDefault();
// display loader
modal.style.display = 'block';
loading.style.display = 'block';
if (validate()) {
const url = 'http://br.bharatrohan.in/api/b2b/send-email';
var user = {
first_name: firstName.value,
last_name: lastName.value,
email: email.value,
phone: phone.value,
message: message.value
}
axios({
method: 'post',
url: url,
data: user
})
.then(function(data) {
loading.style.display = 'none';
done.style.display = 'block';
setTimeout(function() {
modal.style.display = 'none';
}, 1500);
})
.catch(function(err) {
alert('Failed to send data.');
modal.style.display = 'none';
});
} else {
modal.style.display = 'none';
}
}
function validate() {
if (firstName.value === '' || email.value === '') {
alert('please fill all fields !!');
return false;
} else if (!(email.value).match(emailReg)) {
alert('Invalid Email !!');
return false;
} else {
return true;
}
}