2021-07-09 01:59:28 +02:00
|
|
|
$("#blog-archive-button").on("click", function () {
|
|
|
|
let archive = $('#blog-archive');
|
|
|
|
archive.toggle();
|
|
|
|
$(this).html((archive.is(":visible") ? "Hide" : "Show") + " archived posts");
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".blog-cat-button").on("click", function () {
|
|
|
|
let tag = $(this).attr("id");
|
|
|
|
openCategory(tag);
|
|
|
|
history.replaceState(null, null, `#blog-${tag}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
let category = window.location.hash.match(/#blog-(.+)/);
|
|
|
|
openCategory(category && decodeURI(category[1]));
|
|
|
|
|
|
|
|
function openCategory(name) {
|
|
|
|
// if there are no tags that match our name, we display featured
|
|
|
|
if (!name || $(`#blog-${name}`).length <= 0)
|
|
|
|
name = "featured";
|
|
|
|
let all = name == "all";
|
|
|
|
|
|
|
|
// toggle post visibilites
|
|
|
|
$(".blog-entry").each(function () {
|
|
|
|
let e = $(this);
|
|
|
|
if (all || e.hasClass(`blog-tag-${name}`)) {
|
|
|
|
e.show();
|
|
|
|
} else {
|
|
|
|
e.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// show or hide "no archived posts" text
|
2021-09-27 04:12:28 +02:00
|
|
|
$("#no-archived-posts").attr("hidden", $("#blog-archive").children(all ? "*" : `.blog-tag-${name}`).length > 0);
|
2021-07-09 01:59:28 +02:00
|
|
|
// disable the shown category's button
|
|
|
|
$(`.blog-cat-button`).each(function () {
|
|
|
|
$(this).attr("disabled", $(this).attr("id") == name);
|
|
|
|
});
|
|
|
|
}
|