-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfooter-scripts.html
More file actions
113 lines (98 loc) · 3.45 KB
/
footer-scripts.html
File metadata and controls
113 lines (98 loc) · 3.45 KB
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
<!-- TE -->
<script type="module" src="{{ .Site.Params.assetsDir }}/js/tw-elements.umd.min.js"></script>
<!-- THEME SWITCHER -->
<script type="text/javascript" src="/js/theme.js"></script>
<!-- PRISM -->
<script type="text/javascript" src="/js/new-prism.js"></script>
<script type="module">
//Scrollspy
(() => {
const scrollspyClasses = [
'data-[te-spy-active]:border-l-2',
'data-[te-spy-active]:border-solid',
'data-[te-spy-active]:border-l-primary',
'data-[te-spy-active]:text-primary',
'dark:data-[te-spy-active]:border-l-primary-400',
'dark:data-[te-spy-active]:text-primary-400',
];
const menuSection = document.querySelectorAll('menu li');
if (menuSection.length === 0) return;
const addScrollspyClasses = (sections) => {
sections.forEach((section) => {
section.classList.add(...scrollspyClasses);
});
};
const teScrollSpyTo = (event) => {
event.preventDefault();
const hash = event.target.getAttribute('href');
const target = document.getElementById(hash.substring(1));
window.scroll({
top: target.offsetTop - 75,
behavior: 'smooth',
});
if (history.pushState) {
history.pushState(null, null, hash);
} else {
location.hash = hash;
}
};
const deactivateAllMenuSections = (sections) => {
sections.forEach((section) => section.removeAttribute('data-te-spy-active'));
};
const activateMenuSection = (section) => {
section.setAttribute('data-te-spy-active', '');
};
const onWindowScroll = () => {
const SELECTOR_SCROLLSPY_ITEM = '[data-te-spy-item]';
const mainSections = [...document.querySelectorAll(SELECTOR_SCROLLSPY_ITEM)].filter(
(section) => section.getBoundingClientRect().y !== 0
);
const filteredMenuSections = [...document.querySelectorAll('menu li')].filter(
(section) => section.getBoundingClientRect().y !== 0
);
mainSections.forEach((header, i) => {
let rect = header.getBoundingClientRect().y;
if (rect <= 100) {
deactivateAllMenuSections(filteredMenuSections);
if (!filteredMenuSections[i]) {
return;
}
activateMenuSection(filteredMenuSections[i]);
}
});
};
addScrollspyClasses(menuSection);
menuSection.forEach((menuElement) => {
const href = menuElement.querySelector('a');
href.addEventListener('click', teScrollSpyTo, false);
href.addEventListener('click', () => {
setTimeout(() => {
deactivateAllMenuSections(menuSection);
activateMenuSection(menuElement);
}, 300);
});
});
window.addEventListener('scroll', onWindowScroll);
})();
</script>
<script>
const CONFIG = {
docsApiUrl: {{.Site.Params.apiUrl}}
};
</script>
<script type="module" src="{{ .Site.Params.assetsDir }}/js/load-user-data.js"></script>
<script type="module" src="{{ .Site.Params.assetsDir }}/js/auth.js"></script>
<script>
function setCookie(name, value, days) {
const date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
const expires = 'expires=' + date.toUTCString();
document.cookie = name + '=' + value + ';' + expires + ';path=/';
}
fetch('http://ip-api.com/json/')
.then((response) => response.json())
.then((data) => {
const countryCode = data.countryCode;
setCookie('gdpr_country', countryCode, 30);
});
</script>