-
-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathlisting.js
More file actions
139 lines (123 loc) · 3.63 KB
/
listing.js
File metadata and controls
139 lines (123 loc) · 3.63 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
132
133
134
135
136
137
138
139
// This is the JavaScript code for listing of filtered resources in the "all.html" page.
// The all.html page is based on the layout listing.html
//Valid filter inputs for the URL parameters
const validTopics = [
"licenses",
"publicdomain",
"oer",
"oa",
"openscience",
"openpolicy",
"opendata",
];
const validMedia = [
"print",
"video",
"infographic",
"website",
"course",
"slides",
];
const validLanguages = [
"ar",
"de",
"en",
"fr",
"hy",
"it",
"ja",
"ko",
"lg",
"mn",
"pl",
"ro",
"ru",
"sv",
"tl",
];
// Function to get the selected filters for Topic, Medium and Language
function getUrlVars() {
const vars = {};
const filterString = window.location.search.slice(1); // slice(1) removes the "?" from window.location.search
const hashes = filterString.split("&");
hashes.forEach((hash) => {
let validKey;
let validValue;
const [key, value] = hash.split("=");
if (key == "topic" && validTopics.includes(value)) {
validKey = key;
validValue = value;
}
if (key == "medium" && validMedia.includes(value)) {
validKey = key;
validValue = value;
}
if (key == "language" && validLanguages.includes(value)) {
validKey = key;
validValue = value;
}
vars[validKey] = validValue;
});
return vars;
}
// assigning variable to the filters selected by user (retrieved by getUrlVars)
const { topic, language, medium } = getUrlVars();
// Setting every thumbnailbox to display:none by creating a new element "dynamicStyle".
// This "dynamicStyle" element can be used to create all the dynamic styles.
const dynamicStyle = document.createElement("style");
dynamicStyle.type = "text/css";
dynamicStyle.innerHTML = ".thumbnailbox { display: none; }";
document.head.appendChild(dynamicStyle);
// If no filter is selected, display all the resources by "display:block"
if (!topic && !medium && !language) {
dynamicStyle.innerHTML += " .thumbnailbox { display: block; }";
} else {
// If filter(s) is/are selected, display all the resources which have all the filters
let selectedFilters = "";
if (topic) {
selectedFilters += `.${topic}`;
}
if (medium) {
selectedFilters += `.${medium}`;
}
if (language) {
selectedFilters += `.${language}`;
}
dynamicStyle.innerHTML += `${selectedFilters} { display: block; }`;
}
// If user has selected some Topic filter, add class resourcenavtopicknown with "display:block".
// Otherwise, add class resourcenavtopicunknown with "display:block"
// This is for displaying the list of available filters to be selected from
let isFilterSelected = "";
if (topic) {
isFilterSelected += " .resourcenavtopicknown";
} else {
isFilterSelected += " .resourcenavtopicunknown";
}
if (medium) {
isFilterSelected += ", .resourcenavmediumknown";
} else {
isFilterSelected += ", .resourcenavmediumunknown";
}
if (language) {
isFilterSelected += ", .resourcenavlanguageknown";
} else {
isFilterSelected += ", .resourcenavlanguageunknown";
}
dynamicStyle.innerHTML += `${isFilterSelected} { display: block; }`;
document.addEventListener('DOMContentLoaded', function () {
// Check if all thumbnailbox elements are hidden
var thumbnailBoxes = document.querySelectorAll('.thumbnailbox');
var allHidden = true;
thumbnailBoxes.forEach(function (box) {
if (window.getComputedStyle(box).display !== 'none') {
allHidden = false;
}
});
// Show the message if all thumbnailbox elements are hidden
if (allHidden) {
var messageElement = document.getElementById('noThumbnailsMessage');
messageElement.classList.remove('hidden');
messageElement.classList.add('visible');
}
});