-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
225 lines (177 loc) Β· 8.99 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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
document.addEventListener('DOMContentLoaded', function() {
const viewMapBtn = document.getElementById('view-map-btn');
viewMapBtn.addEventListener('click', function() {
document.getElementById('map-section').scrollIntoView({ behavior: 'smooth' });
});
});
document.addEventListener('DOMContentLoaded', function() {
const viewMapBtn = document.getElementById('highlights-btn');
viewMapBtn.addEventListener('click', function() {
document.getElementById('highlights').scrollIntoView({ behavior: 'smooth' });
});
});
document.addEventListener('DOMContentLoaded', function() {
const readMoreBtn = document.getElementById('read-more-btn');
const moreContent = document.getElementById('more-content');
readMoreBtn.addEventListener('click', function() {
if (moreContent.classList.contains('expanded')) {
moreContent.classList.remove('expanded');
readMoreBtn.textContent = 'Read More';
} else {
moreContent.classList.add('expanded');
readMoreBtn.textContent = 'Read Less';
}
});
});
const menuBtn = document.getElementById("menu-btn");
const navLinks = document.getElementById("nav-links");
const menuBtnIcon = menuBtn.querySelector("i");
menuBtn.addEventListener("click", () => {
navLinks.classList.toggle("open");
const isOpen = navLinks.classList.contains("open");
menuBtnIcon.setAttribute("class", isOpen ? "ri-close-line" : "ri-menu-line");
});
navLinks.addEventListener("click", () => {
navLinks.classList.remove("open");
menuBtnIcon.setAttribute("class", "ri-menu-line");
});
const scrollRevealOption = {
distance: "50px",
origin: "bottom",
duration: 1000,
};
// header container
ScrollReveal().reveal(".header__container p", {
...scrollRevealOption,
});
ScrollReveal().reveal(".header__container h1", {
...scrollRevealOption,
delay: 500,
});
// about container
ScrollReveal().reveal(".about__image img", {
...scrollRevealOption,
origin: "left",
});
ScrollReveal().reveal(".about__content .section__subheader", {
...scrollRevealOption,
delay: 500,
});
ScrollReveal().reveal(".about__content .section__header", {
...scrollRevealOption,
delay: 1000,
});
ScrollReveal().reveal(".about__content .section__description", {
...scrollRevealOption,
delay: 1500,
});
ScrollReveal().reveal(".about__btn", {
...scrollRevealOption,
delay: 2000,
});
// event container
ScrollReveal().reveal(".event__card", {
...scrollRevealOption,
interval: 500,
});
// highlight container
ScrollReveal().reveal(".highlight__list li", {
...scrollRevealOption,
interval: 500,
origin: "right",
});
document.addEventListener('DOMContentLoaded', function() {
const chatbotBtn = document.getElementById('chatbot-btn');
const chatboxContainer = document.getElementById('chatbox-container');
const chatboxClose = document.getElementById('chatbox-close');
const chatboxContent = document.getElementById('chatbox-content');
const chatboxInput = document.getElementById('chatbox-input');
const chatboxSend = document.getElementById('chatbox-send');
const micBtn = document.getElementById('chatbox-mic');
const responses = {
"hello": { display: "π Namaste! What would you like to know about the temple?", speak: "Namaste! What would you like to know about the temple" },
"temple": { display: "π The name of the temple is Shree Ramalingeswara Swamy Temple. The Ramalingeshwara Swamy Temple is a 300-year-old sanctuary of devotion with rich heritage and a peaceful environment. To know more visit the about section.", speak: "The name of the temple is Shree Ramalingeswara Swamy Temple The Ramalingeshwara Temple is a 300-year-old sanctuary of devotion with rich heritage and a peaceful environment. To know more visit the about section" },
"location": { display: "π The temple is located in Ramalingapuram, Tamil Nadu. View full address and map location in the contact section.", speak: "The temple is located in Ramalingapuram, Tamil Nadu. View full address and map location in the contact section" },
"timings": { display: "β° The temple is open from 6 AM to 12 PM and 4 PM to 7 PM daily.", speak: "The temple is open from 6 AM to 12 PM and 4 PM to 7 PM daily" },
"dhyana": { display: "π§ The temple's peaceful atmosphere amidst nature and a pond makes it a perfect place for dhyana and meditation.", speak: "The temple's peaceful atmosphere amidst nature and a pond makes it a perfect place for dhyana and meditation" },
"meditation": { display: "π§ The serene environment of the temple is ideal for meditation and finding inner peace.", speak: "The serene environment of the temple is ideal for meditation and finding inner peace" },
"services": { display: "πͺ The temple offers various services including daily poojas, special rituals, and community events.", speak: "The temple offers various services including daily poojas, special rituals, and community events" },
"events": { display: "π We celebrate special Hindu occasions dedicated to Lord Shiva. Check out our past events section.", speak: "We celebrate special Hindu occasions dedicated to Lord Shiva. Check out our past events section" },
"bye": { display: "π Goodbye! Have a great day!", speak: "Goodbye! Have a great day" },
"default": { display: "π I'm sorry, I didn't understand that. Please contact our team for further details. You can find the contact details at the contact section.", speak: "I'm sorry, I didn't understand that. Please contact our team for further details. You can find the contact details at the contact section" }
};
let fromVoice = false; // Flag to track if the message came from voice input
chatbotBtn.addEventListener('click', function() {
chatboxContainer.classList.add('active');
appendMessage('bot', "Namaste! What would you like to know about the temple?");
});
chatboxClose.addEventListener('click', function() {
chatboxContainer.classList.remove('active');
});
chatboxSend.addEventListener('click', sendMessage);
chatboxInput.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
sendMessage();
}
});
micBtn.addEventListener('click', startVoiceRecognition);
function sendMessage() {
const userMessage = chatboxInput.value.trim();
if (userMessage === '') return;
appendMessage('user', userMessage);
chatboxInput.value = '';
const botResponse = getResponse(userMessage.toLowerCase());
setTimeout(() => {
appendMessage('bot', botResponse.display);
if (fromVoice) {
speakResponse(botResponse.speak); // Only speak the response if the input was from voice
fromVoice = false; // Reset the flag after speaking
}
}, 500); // Add a slight delay to mimic real response time
}
function appendMessage(sender, message) {
const messageElem = document.createElement('div');
messageElem.className = sender === 'user' ? 'user-message' : 'bot-message';
const icon = document.createElement('i');
icon.className = sender === 'user' ? 'ri-user-line message-icon' : 'ri-robot-line message-icon';
const text = document.createElement('span');
text.textContent = message;
messageElem.appendChild(icon);
messageElem.appendChild(text);
chatboxContent.appendChild(messageElem);
chatboxContent.scrollTop = chatboxContent.scrollHeight;
}
function getResponse(message) {
if (message.includes('hello') || message.includes('hi')) return responses['hello'];
if (message.includes('location') || message.includes('where') || message.includes('location of temple')) return responses['location'];
if (message.includes('hours') || message.includes('time') || message.includes('timing')) return responses['timings'];
if (message.includes('dhyana')) return responses['dhyana'];
if (message.includes('meditation')) return responses['meditation'];
if (message.includes('services')) return responses['services'];
if (message.includes('about the temple') || message.includes('history')) return responses['temple'];
if (message.includes('events') || message.includes('functions')) return responses['events'];
if (message.includes('temple') || message.includes('name') || message.includes('details')) return responses['temple'];
if (message.includes('bye')) return responses['bye'];
return responses['default'];
}
function startVoiceRecognition() {
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.onresult = function(event) {
const transcript = event.results[0][0].transcript;
chatboxInput.value = transcript;
fromVoice = true; // Set the flag to true when the input is from voice
sendMessage();
};
recognition.onerror = function(event) {
console.error('Voice recognition error:', event.error);
};
recognition.start();
}
function speakResponse(response) {
const utterance = new SpeechSynthesisUtterance(response);
utterance.lang = 'en-US';
window.speechSynthesis.speak(utterance);
}
});