-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
72 lines (61 loc) · 2.66 KB
/
script.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
const whatsappLink = document.getElementById('whatsapp-link');
const questionList = document.getElementById('question-list');
const customQuestionInput = document.getElementById('custom-question');
const questionItems = document.querySelectorAll('#question-list ul li');
const sliderImages = document.querySelectorAll('.slider img');
const contactForm = document.getElementById('contact-form');
// Hide images initially
sliderImages.forEach((img) => img.style.display = 'none');
let currentImageIndex = 0;
// Show first image and start slideshow after 3 seconds
setTimeout(() => {
sliderImages[currentImageIndex].style.display = 'block';
setInterval(() => {
sliderImages[currentImageIndex].style.display = 'none';
currentImageIndex = (currentImageIndex + 1) % sliderImages.length;
sliderImages[currentImageIndex].style.display = 'block';
}, 3000);
}, 3000);
whatsappLink.addEventListener('click', (e) => {
e.preventDefault();
questionList.style.display = 'block';
});
document.addEventListener('click', function(event) {
if (!document.getElementById('question-list').contains(event.target) &&
!document.getElementById('whatsapp-link').contains(event.target)) {
document.getElementById('question-list').style.display = 'none';
}
});
questionItems.forEach((item) => {
item.addEventListener('click', (e) => {
const selectedQuestion = e.target.dataset.message || e.target.textContent;
if (selectedQuestion === 'Other (type your question)') {
customQuestionInput.style.display = 'block';
questionList.style.display = 'none';
} else {
const whatsappUrl = `https://wa.me/+263783298690?text=${encodeURIComponent(selectedQuestion)}`;
whatsappLink.href = whatsappUrl;
questionList.style.display = 'none';
window.open(whatsappUrl, '_blank');
}
});
});
customQuestionInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
const customQuestion = customQuestionInput.value;
const whatsappUrl = `https://wa.me/+263783298690?text=${encodeURIComponent(customQuestion)}`;
whatsappLink.href = whatsappUrl;
questionList.style.display = 'none';
window.open(whatsappUrl, '_blank');
customQuestionInput.style.display = 'none';
customQuestionInput.value = '';
}
});
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
const mailToLink = `mailto:[email protected]?subject=Contact Form Submission&body=Name: ${name}%0AEmail: ${email}%0AMessage: ${message}`;
window.location.href = mailToLink;
});