-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
72 lines (62 loc) · 2.03 KB
/
script.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
document.addEventListener("DOMContentLoaded", function() {
var termLinks = document.querySelectorAll('.term-link');
var termLinkContainer = document.querySelector('.term-link-container'); // Select the container
var backToGlossaryLink = document.querySelector('.back-to-glossary-link');
var termContainers = document.querySelectorAll('[id^="term-content-"]');
var alphabetLinks = document.querySelectorAll('.alphabet-links a');
alphabetLinks.forEach(function(alphabetLink) {
alphabetLink.addEventListener('click', function(event) {
event.preventDefault();
var letter = alphabetLink.textContent;
hideAllTermContainers();
showTermLinkContainer();
filterTermsByLetter(letter);
});
});
termLinks.forEach(function(termLink) {
termLink.addEventListener('click', function(event) {
event.preventDefault();
var termName = termLink.getAttribute('data-term-name');
hideTermLinkContainer();
showTermContent(termName);
});
});
backToGlossaryLink.addEventListener('click', function(event) {
event.preventDefault();
showTermLinkContainer();
hideAllTermContainers();
showAllTermLinks();
});
function filterTermsByLetter(letter) {
termLinks.forEach(function(termLink) {
var termName = termLink.getAttribute('data-term-name');
if (termName && termName.charAt(0).toUpperCase() === letter) {
termLink.style.display = 'inline-block';
} else {
termLink.style.display = 'none';
}
});
}
function hideTermLinkContainer() {
termLinkContainer.style.display = 'none';
}
function showTermLinkContainer() {
termLinkContainer.style.display = 'grid';
}
function showAllTermLinks() {
termLinks.forEach(function(termLink) {
termLink.style.display = 'inline-block';
});
}
function hideAllTermContainers() {
termContainers.forEach(function(container) {
container.style.display = 'none';
});
}
function showTermContent(termName) {
var selectedTermContent = document.getElementById('term-content-' + termName);
if (selectedTermContent) {
selectedTermContent.style.display = 'block';
}
}
});