-
Notifications
You must be signed in to change notification settings - Fork 3
/
unconf.js
89 lines (68 loc) · 2.44 KB
/
unconf.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
class PositionIndicator {
constructor() {
this.currentTab = null;
this.tabContainerHeight = 70;
this.navElements = document.querySelectorAll('nav a[href^="#"]');
this.navElements.forEach((navElement) => {
navElement.addEventListener('click', (event) => this.onTabClick(event));
});
this.onScroll();
window.addEventListener('scroll', () => this.onScroll());
window.addEventListener('resize', () => this.onResize());
}
onTabClick(event) {
event.preventDefault();
const targetArticle = document.querySelector(event.currentTarget.attributes.href.value);
window.scrollTo({
top: targetArticle.offsetTop - this.tabContainerHeight,
behavior: 'smooth'
});
}
onScroll() {
this.findCurrentTabSelector();
}
onResize() {
this.setSliderCss();
}
findCurrentTabSelector(element) {
let currentNavElement;
this.navElements.forEach((navElement) => {
const idSelector = navElement.attributes.href.value;
const article = document.querySelector(idSelector);
if (article.getBoundingClientRect().top < (window.innerHeight / 2)) {
currentNavElement = navElement;
}
});
const fakeTab = { href: '' };
if ((this.currentTab || fakeTab).href !== (currentNavElement || fakeTab).href) {
this.currentTab = currentNavElement;
this.setSliderCss();
}
}
setSliderCss() {
const sliderElement = document.querySelector('nav .slider');
const tabDimensions = this.currentTab ? this.currentTab.getBoundingClientRect() : { width: 0, left: 0 };
sliderElement.style.width = tabDimensions.width;
sliderElement.style.left = tabDimensions.left;
}
}
new PositionIndicator();
// map
const initialiseMap = () => {
if (!mapboxgl) { window.setTimeout(100, initialiseMap()); return }
mapboxgl.accessToken = 'pk.eyJ1IjoiZW1yb3giLCJhIjoiY2pvMzE4dnAzMHE3dzNrcGFuajdoa2duZSJ9.qiLN60PNBVjW4pivjwVtvQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [10.03, 53.56],
zoom: 11
});
map.addControl(new mapboxgl.NavigationControl());
map.setStyle('mapbox://styles/emrox/ck3wycjf73c2m1cll16jzxbuk');
const markerElelemt = document.createElement('div');
markerElelemt.className = 'map__marker';
new mapboxgl.Marker(markerElelemt).setLngLat({ lng: 10.034110, lat: 53.569130 }).addTo(map);
}
if (document.querySelector('#map')) {
window.setTimeout(100, initialiseMap());
}