-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
131 lines (118 loc) · 4.38 KB
/
Copy pathindex.js
File metadata and controls
131 lines (118 loc) · 4.38 KB
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
// front matter linter for genres--must have one genre true, must only have allowed genres, no dup genres
// get asteroid story
function show(genre) {
// For each element with class "story",
// if the element also has the input genre in its class,
// add the class "show"
let storyDivs = document.getElementsByClassName("story");
Array.from(storyDivs).forEach(storyDiv => {
if (storyDiv.classList.contains(genre)) storyDiv.classList.add("show")
});
}
function hide(genre) {
// Figure out which genres are checked
let checkboxes = document.getElementsByClassName('genre');
let checkedGenres = Array.from(checkboxes)
.filter(checkbox => checkbox.checked)
.map(checkbox => checkbox.name);
// For each element with class "story",
// If the story's genres do not match any of the checked genres,
// remove the class "show"
let storyDivs = document.getElementsByClassName("story");
Array.from(storyDivs).forEach(storyDiv => {
if (storyDiv.classList.contains(genre)) {
let checkedStoryGenres = checkedGenres.filter(checked => storyDiv.classList.contains(checked));
if (!checkedStoryGenres.length) {
storyDiv.classList.remove("show");
}
}
})
}
function showAll() {
// For each element with class "story",
// add the class "show"
let storyDivs = document.getElementsByClassName("story");
Array.from(storyDivs).forEach(storyDiv => storyDiv.classList.add("show"));
}
function hideAll() {
// For each element with class "story",
// remove the class "show"
let storyDivs = document.getElementsByClassName("story");
Array.from(storyDivs).forEach(storyDiv => storyDiv.classList.remove("show"));
}
function toggleGenre(source, genre) {
if (source.checked) {
show(genre);
} else {
hide(genre);
// Uncheck the "Show All" box
let checkAllBox = document.getElementById("checkAll")
checkAllBox.checked = false;
}
}
function toggleAll(source) {
// Show or hide all stories when the "Show All" box is checked
if (source.checked) {
showAll();
} else {
hideAll();
}
// Make the other checkboxes match the state of the "Show All" checkbox
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
Array.from(checkboxes).forEach(checkbox => { if (checkbox != source) checkbox.checked = source.checked })
}
function expandCollapseAll(source) {
let expandables = document.getElementsByTagName("details");
if (source.innerHTML == "Expand All") {
// Change the button text and expand all
source.innerHTML = "Collapse All";
Array.from(expandables).forEach(expandable => expandable.setAttribute("open", ""))
} else {
// Change the button text and collapse all
source.innerHTML = "Expand All";
Array.from(expandables).forEach(expandable => expandable.removeAttribute("open"))
}
}
function reverseOrder(source) {
// Change the button text and reverse row order
let stories = document.getElementById("stories");
if (source.innerHTML == "Oldest First") {
source.innerHTML = "Newest first";
stories.style.flexDirection = "column-reverse"
} else {
source.innerHTML = "Oldest First";
stories.style.flexDirection = "column"
}
}
function toggleMenu() {
// Show or hid the menu controls
let menu = document.getElementById("controls");
if (menu.style.display === "flex") {
menu.style.display = "none";
} else {
menu.style.display = "flex";
}
}
function changeFont(increment) {
// These are the supported font-size key words
// It would be better to avoid hard-coding this, but also make sure the
// font-size is accessibility-friendly (e.g. still don't specify pixel font sizes)
sizes = [
"xx-small",
"x-small",
"small",
"medium",
"large",
"x-large",
"xx-large",
"xxx-large"
];
let stories = document.getElementById("stories");
// If font-size is not set, use medium
let currentSize = stories.style["font-size"] ? stories.style["font-size"] : "medium";
// Set the new font size to the next size up (unless the font size is maxed out)
let newSize = sizes[sizes.indexOf(currentSize) + increment];
if (newSize) {
stories.style["font-size"] = newSize
}
}