/
index.js
111 lines (101 loc) · 3.66 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
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
let i = 0;
scrollButton = document.getElementById('scrollButton');
homeBtn = document.getElementById('home');
document.addEventListener('DOMContentLoaded', () => {
let homeAnimation = localStorage.getItem('homeAnimation') || true;
// Toggle animation on button press
const btn = document.getElementById('homeAnimationToggleBtn');
btn.addEventListener('click', () => {
homeBtn.classList.toggle('animate');
if (homeAnimation) {
homeAnimation = false;
} else {
homeAnimation = true;
}
localStorage.setItem('homeAnimation', homeAnimation);
});
if (!homeAnimation) {
console.log('HomeAnimation is false!')
homeBtn.classList.remove('animate');
}
});
function scrollButtonBehavior() {
if (document.body.scrollTop > 1000 || document.documentElement.scrollTop > 1000) {
scrollButton.title='scroll to top';
scrollButton.setAttribute('aria-label', 'scroll to top');
scrollButton.classList.remove('scrollToBottom');
} else {
scrollButton.title='scroll to bottom';
scrollButton.setAttribute('aria-label', 'scroll to bottom');
scrollButton.classList.add('scrollToBottom');
};
}
function nowScroll() {
if (document.body.scrollTop > 1000 || document.documentElement.scrollTop > 1000) {
window.scrollTo(0, 0);
} else {
window.scrollTo(0, document.body.scrollHeight);
}
}
window.onload = function() {
scrollButtonBehavior();
window.onscroll = function() {
scrollButtonBehavior();
};
};
/******************
* Language filter *
*******************/
let Italian = document.querySelectorAll('.zibaldone a[hreflang=it], .grid a[hreflang=it]');
let nonItalian = document.querySelectorAll('.zibaldone a[hreflang=en], .grid a[hreflang=en], .zibaldone a[hreflang=fr], .grid a[hreflang=fr]');
let English = document.querySelectorAll('.zibaldone a[hreflang=en], .grid a[hreflang=en]');
let nonEnglish = document.querySelectorAll('.zibaldone a[hreflang=it], .grid a[hreflang=it], .zibaldone a[hreflang=fr], .grid a[hreflang=fr]');
let French = document.querySelectorAll('.zibaldone a[hreflang=fr], .grid a[hreflang=fr]');
let nonFrench = document.querySelectorAll('.zibaldone a[hreflang=it], .grid a[hreflang=it], .zibaldone a[hreflang=en], .grid a[hreflang=en]');
let allLang = document.querySelectorAll('.zibaldone a[hreflang=it], .grid a[hreflang=it], .zibaldone a[hreflang=en], .grid a[hreflang=en], .zibaldone a[hreflang=fr], .grid a[hreflang=fr]');
function toggleIt() {
for (i = 0; i < nonItalian.length; i++) {
nonItalian[i].style.display = 'none';
}
for (i = 0; i < Italian.length; i++) {
Italian[i].style.display = 'block';
}
}
function toggleEn() {
for (i = 0; i < nonEnglish.length; i++) {
nonEnglish[i].style.display = 'none';
}
for (i = 0; i < English.length; i++) {
English[i].style.display = 'block';
}
}
function toggleFr() {
for (i = 0; i < nonFrench.length; i++) {
nonFrench[i].style.display = 'none';
}
for (i = 0; i < French.length; i++) {
French[i].style.display = 'block';
}
}
function toggleAll() {
for (i = 0; i < allLang.length; i++) {
allLang[i].style.display = 'block';
}
}
window.addEventListener('load', () => {
if (document.querySelectorAll('[data-target-lang]')) {
for (const button of document.querySelectorAll('[data-target-lang=en]')) {
button.addEventListener('click', toggleEn);
};
for (const button of document.querySelectorAll('[data-target-lang=fr]')) {
button.addEventListener('click', toggleFr);
};
for (const button of document.querySelectorAll('[data-target-lang=it]')) {
button.addEventListener('click', toggleIt);
};
for (const button of document.querySelectorAll('[data-target-lang=all]')) {
button.addEventListener('click', toggleAll);
};
};
scrollButton.addEventListener('click', nowScroll);
});