-
Notifications
You must be signed in to change notification settings - Fork 24
/
scripts.js
146 lines (128 loc) Β· 4.78 KB
/
scripts.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// var Plyr = require('./lib/plyr.polyfilled');
window.addEventListener('load', function() {
var headerHeight = document.querySelector('.page-header').clientHeight;
var stickyNavbarElement = document.querySelector('.navbar-sticky');
var offset = 300;
toggleStickyNavbar();
window.addEventListener('scroll', function() {
toggleStickyNavbar();
});
function toggleStickyNavbar() {
if (window.scrollY > headerHeight - offset) {
return stickyNavbarElement.classList.add('visible');
}
stickyNavbarElement.classList.remove('visible');
}
// var player = new Plyr('#player', {
// keyboard: {
// global: true,
// },
// });
// player.once('play', function() {
// var videoWrapper = document.querySelector('.plyr__video-wrapper');
// videoWrapper.classList.add('hidden-poster');
// const poster = videoWrapper.querySelector('.plyr__poster');
// if (poster) {
// poster.remove();
// }
// });
registerNavigation();
function registerNavigation() {
var elements = document.querySelectorAll('.nav-wrapper a');
elements.forEach(function(el) {
const href = el.getAttribute('href') || '';
const isAnchor = href[0] === '#';
if (!isAnchor) {
return;
}
el.addEventListener('click', function(event) {
if (!el.scrollIntoView) {
return;
}
event.preventDefault();
var targetElement = document.querySelector(el.getAttribute('href'));
if (targetElement) {
targetElement.scrollIntoView({ block: 'start', behavior: 'smooth' });
}
});
});
}
const newsletterAddButton = document.querySelector('.newsletter-form button');
const newsletterEmailInput = document.querySelector('#newsletter-email');
const formRef = document.querySelector('.newsletter-form form');
if (newsletterAddButton && newsletterEmailInput) {
formRef.addEventListener('submit', function(e) {
e.preventDefault();
newsletterAddButton.setAttribute('disabled', 'disabled');
newsletterEmailInput.setAttribute('disabled', 'disabled');
const value = newsletterEmailInput.value;
const xhr = new XMLHttpRequest();
const url =
'https://nbdggbnqnrevwg6xlex3st3vpe0nyhiq.lambda-url.us-east-2.on.aws/?token=db1f899025b5a59a76b6b34b2a013893';
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function() {
newsletterAddButton.classList.add('btn-success');
};
const data = JSON.stringify({ email: value });
xhr.send(data);
});
}
const body = this.document.querySelector('body');
const mobileNavIcon = this.document.querySelector('.mobile-nav-icon');
const mobileNav = this.document.querySelector('.mobile-nav');
const mobileNavClose = this.document.querySelector('.mobile-nav-close');
mobileNavIcon.addEventListener('click', function() {
mobileNav.classList.add('open');
body.classList.add('mobile-nav-open');
});
mobileNavClose.addEventListener('click', function() {
mobileNav.classList.remove('open');
body.classList.remove('mobile-nav-open');
});
// Sponsors
const fetchBronzeSponsorsUrl = `https://opencollective.com/nest/tiers/bronze-sponsors/all.json`;
fetch(fetchBronzeSponsorsUrl, {
method: 'GET',
headers: {
Accept: 'application/json',
},
})
.then((response) => response.json())
.then((data) => {
if (!data) {
return;
}
const activeSponsors = data.filter((sponsor) => sponsor.isActive);
const bronzeSponsorsContainer = document.querySelector('.bronze-sponsors-container');
if (!bronzeSponsorsContainer) {
return;
}
activeSponsors.filter(item => item.image).forEach((sponsor) => {
const sponsorElement = document.createElement('a');
sponsorElement.href = sponsor.website;
sponsorElement.target = '_blank';
sponsorElement.rel = 'noopener noreferrer';
sponsorElement.title = sponsor.name;
sponsorElement.innerHTML = `<img src="${sponsor.image}" alt="${sponsor.name}" loading="lazy" />`;
bronzeSponsorsContainer.appendChild(sponsorElement);
});
});
// Footer year
document.getElementById('currentYear').textContent = new Date().getFullYear();
// Only load iframe when it's in view to improve performance
const iframe = document.querySelector('#preview iframe');
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
iframe.src = iframe.dataset.src;
observer.disconnect();
}
});
});
observer.observe(iframe);
// Disconnect observer on unload
window.addEventListener('beforeunload', () => {
observer.disconnect();
});
});