forked from mansiruhil13/Bobble-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
174 lines (140 loc) · 5.86 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
let script = document.createElement('script');
script.src = "https://cdn.gtranslate.net/widgets/latest/float.js"; // URL of the external script
script.defer = true; // Ensures the script runs after parsing the HTML
document.body.appendChild(script); // Add the script to the body
window.gtranslateSettings = { "default_language": "en", "detect_browser_language": true, "wrapper_selector": ".gtranslate_wrapper" }
// Function to change the active class when a link is clicked
function changeContent(page) {
var links = document.querySelectorAll(".menu ul li a");
// Remove "active" class from all links
links.forEach((link) => link.classList.remove("active"));``
// Add "active" class to the current page link
var activeLink = document.getElementById(page + "-link");
if (activeLink) {
activeLink.classList.add("active");
} else {
console.error(`Link with id ${page + '-link'} not found`);
}
console.log(page + "-link");
}
const currentLanguage = window.gtranslateSettings.current_language;
const ambuFlowText = document.querySelector(".main_heading h2[data-link_h2='AmbuFlow...']");
if (currentLanguage === 'gu' || currentLanguage === 'hi') {
ambuFlowText.style.display = 'none'; // Hide text for Gujarati and Hindi
} else {
ambuFlowText.style.display = 'block'; // Show text for other languages
}
// Function that runs when the window loads
window.onload = function () {
// Assuming you are using the URL or some global variable to determine the page
var currentPage = window.location.pathname.split("/").pop().replace(".html", "");
if (currentPage) {
changeContent(currentPage);
}
// Add delay to each letter drop
const letters = document.querySelectorAll('.letter');
letters.forEach((letter, index) => {
letter.style.animationDelay = `${index * 0.1}s`;
});
};
// JS for dark mode functionality
// adding code for dark mode
document.addEventListener("DOMContentLoaded", () => {
const darkModeButton = document.getElementById("dark-mode-button");
// Check sessionStorage for dark mode preference
const currentTheme = sessionStorage.getItem("theme");
if (currentTheme === "dark") {
document.body.classList.add("dark-mode");
document.body.classList.remove("light-mode");
darkModeButton.innerHTML = '<i class="fa-solid fa-sun"></i>'; // Change icon
} else {
document.body.classList.add("light-mode");
document.body.classList.remove("dark-mode");
darkModeButton.innerHTML = '<i class="fa-solid fa-moon"></i>'; // Change icon
}
darkModeButton.addEventListener("click", () => {
document.body.classList.toggle("dark-mode");
document.body.classList.toggle("light-mode");
// Save preference to sessionStorage
if (document.body.classList.contains("dark-mode")) {
sessionStorage.setItem("theme", "dark");
darkModeButton.innerHTML = '<i class="fa-solid fa-sun"></i>'; // Change icon
} else {
sessionStorage.setItem("theme", "light");
darkModeButton.innerHTML = '<i class="fa-solid fa-moon"></i>'; // Change icon
}
});
});
//For Translator
window.gtranslateSettings = {
"default_language": "en",
"detect_browser_language": true,
"wrapper_selector": ".gtranslate_wrapper",
"alt_flags": { "en": "usa" }
}
const translateBtn = document.getElementById('translateBtn');
const gTranslate = document.getElementById('gTranslate');
translateBtn.addEventListener('click', function () {
if (gTranslate.style.display === 'none') {
gTranslate.style.display = 'block';
} else {
gTranslate.style.display = 'none';
}
});
// Close the translator popup when clicking outside
document.addEventListener('click', function (event) {
if (!gTranslate.contains(event.target) && event.target !== translateBtn) {
gTranslate.style.display = 'none';
}
});
// Newsletter form submission handler
document
.getElementById("newsletter-form")
.addEventListener("submit", function (event) {
event.preventDefault(); // Prevent the form from submitting normally
const emailInput = document.getElementById("email");
const confirmationMessage = document.getElementById("confirmation-message");
// Optionally send the email to your backend
const email = emailInput.value;
// Simulate a successful submission (you could replace this with an actual API call)
console.log(`Email submitted: ${email}`); // For debugging
// Display the confirmation message
confirmationMessage.textContent =
"Thank you for subscribing! Please check your email for further instructions.";
confirmationMessage.classList.remove("hidden");
// Clear the form
emailInput.value = "";
});
// Accordion functionality
const accordions = document.querySelectorAll(".accordion");
accordions.forEach((accordion, index) => {
const header = accordion.querySelector(".accordion__header");
const content = accordion.querySelector(".accordion__content");
const icon = accordion.querySelector(".accordion__icon i");
header.addEventListener("click", () => {
const isOpen = content.style.height === `${content.scrollHeight}px`;
accordions.forEach((a, i) => {
const c = a.querySelector(".accordion__content");
const ic = a.querySelector(".accordion__icon i");
if (i === index) {
c.style.height = isOpen ? "0px" : `${c.scrollHeight}px`;
ic.classList.toggle("ri-add-line", isOpen);
ic.classList.toggle("ri-subtract-fill", !isOpen);
} else {
c.style.height = "0px";
ic.classList.add("ri-add-line");
ic.classList.remove("ri-subtract-fill");
}
});
});
});
// Back to top button functionality
const backToTopButton = document.getElementById('back-to-top');
// Show the button when scrolled down 100px from the top
window.onscroll = function () {
if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
backToTopButton.style.display = "block";
} else {
backToTopButton.style.display = "none";
}
};