-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
61 lines (50 loc) · 1.99 KB
/
main.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
const toggle = document.getElementById('theme-toggle');
// Get the current theme from Local Storage
const currentTheme = localStorage.getItem('theme');
// If the current theme is 'dark', set the toggle to checked and add the dark class to the HTML element
if (currentTheme === 'dark') {
toggle.checked = true;
document.documentElement.classList.add('dark');
}
// Add an event listener to the toggle to listen for changes
toggle.addEventListener('change', function(event) {
if (event.target.checked) {
// If the toggle is checked, add the 'dark' class to the HTML element
document.documentElement.classList.add('dark');
// Save the theme to Local Storage
localStorage.setItem('theme', 'dark');
} else {
// If the toggle is not checked, remove the 'dark' class from the HTML element
document.documentElement.classList.remove('dark');
// Save the theme to Local Storage
localStorage.setItem('theme', 'light');
}
});
//Language
function translatePage(language) {
// Create an object to hold translations
var translations = {};
// Populate the translations object based on the selected language
switch (language) {
case 'es':
translations.title = 'Título en español';
translations.subtitle = 'Subtítulo en español';
// add more translations as needed
break;
case 'fr':
translations.title = 'Titre en français';
translations.subtitle = 'Sous-titre en français';
// add more translations as needed
break;
default:
translations.title = 'Title in English';
translations.subtitle = 'Subtitle in English';
// add more translations as needed
break;
}
// Use jQuery or vanilla JavaScript to replace the text of each element
// with its translated value from the translations object
$('h1').text(translations.title);
$('h2').text(translations.subtitle);
// add more elements as needed
}