-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
32 lines (27 loc) · 1.04 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
document.addEventListener("DOMContentLoaded", function() {
// Remove `no-js` class from <html>
var html = document.querySelector('html');
html.classList.remove('no-js');
html.classList.add('js');
// Accordionize the sections
var sections = document.querySelectorAll('section, aside');
Array.prototype.forEach.call(sections, function(section, i) {
// Collapse all but the first section
section
.querySelector('.section-body')
.setAttribute('aria-hidden', (i > 0 ? 'true' : 'false'));
// Add click handler to section titles to toggle active section
var sectionTitle = section.querySelector('.section-title');
if (sectionTitle) {
sectionTitle.addEventListener('click', function() {
// Collapse active section
var activeSectionBody = document.querySelector('.section-body[aria-hidden="false"]');
activeSectionBody && activeSectionBody.setAttribute('aria-hidden', 'true');
// Show clicked section
sectionTitle
.parentNode.querySelector('.section-body')
.setAttribute('aria-hidden', 'false');
});
};
});
});