list available languages and topics for links, and allow for their dynamic display
This commit is contained in:
47
themes/hugo-sustain/static/js/filter-tags.js
Normal file
47
themes/hugo-sustain/static/js/filter-tags.js
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Max Mehl <https://mehl.mx>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
function selectTag(tag) {
|
||||
let li_tags = document.querySelectorAll('li.link');
|
||||
|
||||
for (i = 0; i < li_tags.length; i++) {
|
||||
tags = li_tags[i].getAttribute('tags');
|
||||
if (tags.indexOf(tag) !== -1) {
|
||||
li_tags[i].style.display = "list-item";
|
||||
} else {
|
||||
li_tags[i].style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
let a_tags = document.querySelectorAll('a.tag');
|
||||
|
||||
for (i = 0; i < a_tags.length; i++) {
|
||||
tags = a_tags[i].getAttribute('tags');
|
||||
if (tags.indexOf(tag) !== -1) {
|
||||
a_tags[i].classList.add("active");
|
||||
} else {
|
||||
a_tags[i].classList.remove("active");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function selectAllTags() {
|
||||
let li_tags = document.querySelectorAll('li.link');
|
||||
|
||||
for (i = 0; i < li_tags.length; i++) {
|
||||
li_tags[i].style.display = "list-item";
|
||||
}
|
||||
|
||||
let a_tags = document.querySelectorAll('a.tag');
|
||||
|
||||
for (i = 0; i < a_tags.length; i++) {
|
||||
tags = a_tags[i].getAttribute('tags');
|
||||
if (tags == "all") {
|
||||
a_tags[i].classList.add("active");
|
||||
} else {
|
||||
a_tags[i].classList.remove("active");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user