-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
116 lines (101 loc) · 4.35 KB
/
main.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
document.addEventListener("DOMContentLoaded", function () {
const collapseAllButton = document.getElementById("collapse-all-button");
const detailsContainer = document.getElementById("details-container");
if (collapseAllButton && detailsContainer) {
const detailsElements = detailsContainer.getElementsByTagName("details");
collapseAllButton.addEventListener("click", function () {
for (const detailsElement of detailsElements) {
detailsElement.open = false;
}
});
} else {
// Reload the page if required elements are not found
window.location.reload();
}
});
// __________________________________________________________
// __________________________________________________________
// Show the BUTTON when the collapsibles are open if not hide it
// __________________________________________________________
// __________________________________________________________
document.addEventListener("DOMContentLoaded", function () {
const buttonContainer = document.getElementById("collapse-all-button");
const detailsElements = document.querySelectorAll("details");
// sourcery skip: avoid-function-declarations-in-blocks
function toggleCollapseButtonVisibility() {
const isAnyDetailsOpen = Array.from(detailsElements).some(
(detailsElement) => detailsElement.open
);
if (isAnyDetailsOpen) {
buttonContainer.classList.remove("hidden");
} else {
buttonContainer.classList.add("hidden");
}
}
buttonContainer.addEventListener("click", function () {
for (const detailsElement of detailsElements) {
detailsElement.open = false;
}
});
// Initially, check for visibility
toggleCollapseButtonVisibility();
// Listen for changes in details elements
detailsElements.forEach((detailsElement) => {
detailsElement.addEventListener("toggle", toggleCollapseButtonVisibility);
});
});
// __________________________________________________________
// HERE WE ARE ADDING TAILWIND CLASSES TO EACH OL ELEMENT
// __________________________________________________________
function addClassesToSelector(selector, classes) {
document.querySelectorAll(selector).forEach((element) => {
classes.forEach((cls) => element.classList.add(cls));
});
}
function fetchAndDisplayCsvData(csvFilePath, targetElementId) {
fetch(csvFilePath)
.then((response) => response.text())
.then((data) => {
const rows = data.split("\n");
// const headers = rows[0].split(",");
const targetElement = document.getElementById(targetElementId);
for (let i = 1; i < rows.length; i++) {
const cols = rows[i].split(",");
const li = document.createElement("li");
const a = document.createElement("a");
const p = document.createElement("p");
const ranking = document.createElement("p");
a.href = cols[0];
a.innerHTML = "<b class='links'>" + cols[1] + "</b>";
a.target = "_blank";
a.rel = "noopener noreferrer";
p.textContent = cols[2];
ranking.textContent = cols[3];
li.appendChild(a);
li.appendChild(p);
li.appendChild(ranking);
targetElement.appendChild(li);
}
});
}
document.addEventListener("DOMContentLoaded", function () {
// Fetch and display data for each category
fetchAndDisplayCsvData("./data/teachers.csv", "teachers");
fetchAndDisplayCsvData("./data/speaking.csv", "speaking");
fetchAndDisplayCsvData("./data/listening.csv", "listening");
fetchAndDisplayCsvData("./data/reading.csv", "reading");
fetchAndDisplayCsvData("./data/writing.csv", "writing");
fetchAndDisplayCsvData("./data/pronunciation.csv", "pronunciation");
fetchAndDisplayCsvData("./data/phrasal_verbs.csv", "phrasal-verbs");
fetchAndDisplayCsvData("./data/collocations.csv", "collocations");
fetchAndDisplayCsvData("./data/vocab.csv", "vocab");
fetchAndDisplayCsvData("./data/grammar.csv", "grammar");
fetchAndDisplayCsvData("./data/fce.csv", "fce");
fetchAndDisplayCsvData("./data/cae.csv", "cae");
fetchAndDisplayCsvData("./data/dictionaries.csv", "dictionaries");
fetchAndDisplayCsvData("./data/top.csv", "top-resources");
fetchAndDisplayCsvData("./data/young_learners.csv", "young-learners");
// Add Tailwind classes to elements
addClassesToSelector("ol", ["list-decimal", "pl-8", "pt-4"]);
addClassesToSelector("summary", ["text-base", "sm:text-lg", "md:text-xl"]);
});