-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (46 loc) · 1.95 KB
/
index.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
function showMorty(e){
console.log(e.target.getAttribute('data-visible'))
if(e.target.getAttribute('data-visible') === 'false'){
e.target.setAttribute('data-visible', 'true')
var randomParam = '?t=' + new Date().getTime();
e.target.style.backgroundImage = 'url(https://media1.tenor.com/m/-9ObxBks2acAAAAd/%D1%80%D0%B8%D0%BA-%D1%80%D0%B8%D0%BA-%D0%B8-%D0%BC%D0%BE%D1%80%D1%82%D0%B8.gif' + randomParam + ')';
setTimeout(function () {
e.target.style.backgroundImage = 'none';
e.target.setAttribute('data-visible', 'false');
}, 5000);
}else{
e.target.setAttribute('data-visible', 'false')
e.target.style.backgroundImage = 'none';
}
}
document.addEventListener("DOMContentLoaded", function () {
const buttonLang = document.querySelector('.change_lang');
buttonLang.addEventListener('click', changeURLLanguage);
function changeURLLanguage() {
const currentLang = buttonLang.getAttribute('data-lang');
const newLang = currentLang === 'ru' ? 'en' : 'ru';
// Update the language attribute for the button
buttonLang.setAttribute('data-lang', newLang);
// Update text content for each element
updateLanguage(newLang);
// Update the text on the button
buttonLang.textContent = currentLang.toUpperCase();
}
function updateLanguage(lang) {
fetch('translations.json')
.then(response => response.json())
.then(translations => {
Object.keys(translations).forEach(key => {
const element = document.querySelector(`[data-lang-key="${key}"]`);
if (element) {
if(element.tagName === 'INPUT' && element.getAttribute('placeholder')){
element.setAttribute('placeholder', translations[key][lang])
}else{
element.textContent = translations[key][lang];
}
}
});
})
.catch(error => console.error('Error fetching translations:', error));
}
});