made the current category button disabled
All checks were successful
Web/pipeline/head This commit looks good

This commit is contained in:
Ell 2021-03-24 17:38:02 +01:00
parent cbe4a615df
commit 71c5f58d30

View file

@ -22,10 +22,10 @@ function populateBlog(json, cat) {
list.html(""); list.html("");
cats.html(""); cats.html("");
addCatButton(json, cats, "All"); addCatButton(json, cats, "All", cat);
for (let i = json.length - 1; i >= 0; i--) { for (let i = json.length - 1; i >= 0; i--) {
let obj = json[i]; let obj = json[i];
addCatButton(json, cats, obj.cat); addCatButton(json, cats, obj.cat, cat);
if (cat === "All" || obj.cat === cat) { if (cat === "All" || obj.cat === cat) {
let p = /*html*/ ` let p = /*html*/ `
<div class="card bg-light blog-entry rounded-0"> <div class="card bg-light blog-entry rounded-0">
@ -49,10 +49,10 @@ function populateBlog(json, cat) {
archive.html(`<em>There are no archived ${cat} posts.</em>`); archive.html(`<em>There are no archived ${cat} posts.</em>`);
} }
function addCatButton(json, cats, cat) { function addCatButton(json, cats, cat, currCat) {
let catAnchor = `blog-cat-${cat.toLowerCase().replace(" ", "_")}`; let catAnchor = `blog-cat-${cat.toLowerCase().replace(" ", "_")}`;
if (!$(`#${catAnchor}`).length) { if (!$(`#${catAnchor}`).length) {
cats.append( /*html*/ `<button type="button" class="btn btn-link blog-cat-button" id=${catAnchor}>${cat}</button>`); cats.append( /*html*/ `<button type="button" class="btn btn-link blog-cat-button" id=${catAnchor} ${cat === currCat ? "disabled" : ""}>${cat}</button>`);
$(`#${catAnchor}`).on('click', function () { $(`#${catAnchor}`).on('click', function () {
populateBlog(json, cat); populateBlog(json, cat);
}); });