-
Notifications
You must be signed in to change notification settings - Fork 285
/
script.js
171 lines (144 loc) · 5.91 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
document.addEventListener("DOMContentLoaded", function () {
const preloader = document.getElementById("preloader");
if (preloader) {
preloader.style.display = "none"; // Hide preloader after page load
} else {
console.error("Element with ID 'preloader' not found.");
}
const darkModeButton = document.getElementById("dark-mode-button");
// Check if darkModeButton exists before proceeding
if (darkModeButton) {
// Dark mode and light mode functions
const applyDarkMode = () => {
document.body.classList.add("dark-mode");
document.body.classList.remove("light-mode");
darkModeButton.innerHTML = '<i class="fa-solid fa-sun"></i>'; // Set icon to sun
document.body.style.backgroundColor = "rgba(50, 50, 50, 0.95)";
document.body.style.color = "white";
};
const applyLightMode = () => {
document.body.classList.add("light-mode");
document.body.classList.remove("dark-mode");
darkModeButton.innerHTML = '<i class="fa-solid fa-moon"></i>'; // Set icon to moon
document.body.style.backgroundColor = ""; // Reset to default
document.body.style.color = ""; // Reset to default
};
// Apply the current theme from sessionStorage on load
const currentTheme = sessionStorage.getItem("theme");
if (currentTheme === "dark") {
applyDarkMode();
} else {
applyLightMode();
}
// Toggle dark mode on button click
darkModeButton.addEventListener("click", () => {
if (document.body.classList.contains("dark-mode")) {
sessionStorage.setItem("theme", "light");
applyLightMode();
} else {
sessionStorage.setItem("theme", "dark");
applyDarkMode();
}
});
} else {
console.warn("Element with ID 'dark-mode-button' not found.");
}
});
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) {
const 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
const activeLink = document.getElementById(page + "-link");
if (activeLink) {
activeLink.classList.add("active");
} else {
console.error(`Link with id ${page + '-link'} not found`);
}
}
// Language-based content visibility
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 () {
const currentPage = window.location.pathname.split("/").pop().replace(".html", "");
if (currentPage) {
changeContent(currentPage);
}
// Add delay to each letter drop animation
const letters = document.querySelectorAll('.letter');
letters.forEach((letter, index) => {
letter.style.animationDelay = `${index * 0.1}s`;
});
};
// Dark mode functionality
// Translator toggle functionality
const translateBtn = document.getElementById('translateBtn');
const gTranslate = document.getElementById('gTranslate');
translateBtn.addEventListener('click', () => {
gTranslate.style.display = gTranslate.style.display === 'none' ? 'block' : 'none';
});
// Close the translator popup when clicking outside
document.addEventListener('click', (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");
const email = emailInput.value;
console.log(`Email submitted: ${email}`); // For debugging
confirmationMessage.textContent = "Thank you for subscribing! Please check your email for further instructions.";
confirmationMessage.classList.remove("hidden");
emailInput.value = ""; // Clear the form
});
// 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');
window.onscroll = function () {
if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
backToTopButton.style.display = "block";
} else {
backToTopButton.style.display = "none";
}
};