Skip to content

Commit

Permalink
Fix post display on first page
Browse files Browse the repository at this point in the history
  • Loading branch information
liang2kl committed Jun 6, 2023
1 parent 6e8c3ca commit 02ecc24
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions mkdocs_blogging_plugin/templates/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,46 @@ function scrollToTop() {
}, 100);
}

const onButtonClick = (ele) => {
var current = pagination.getElementsByClassName("active");
if (current.length) {
current[0].className = current[0].className.replace(
" active", ""
);
}
ele.className += " active";

// Togglg visibility of pages
const destPage = parseInt(ele.textContent)
var pages = document.getElementsByClassName("page")
if (destPage && pages.length) {
for (var j = 0; j < pages.length; j++) {
const pageId = parseInt(pages[j].id.replace("page", ""))
if (pageId != destPage) {
// This is not the destination page
if (!pages[j].className.includes("blog-hidden")) {
pages[j].className += " blog-hidden"
}
} else {
// This is the destination page
pages[j].className = pages[j].className.replace(" blog-hidden", "")
}
}
scrollToTop();
}
};

var pagination = document.getElementById("blog-pagination");
if (pagination) {
var links = pagination.getElementsByClassName("page-number");
if (links.length) {
for (var i = 0; i < links.length; i++) {
// Toggle pagination highlight
links[i].addEventListener("click", function () {
var current = pagination.getElementsByClassName("active");
if (current.length) {
current[0].className = current[0].className.replace(
" active", ""
);
}
this.className += " active";

// Togglg visibility of pages
const destPage = parseInt(this.textContent)
var pages = document.getElementsByClassName("page")
if (destPage && pages.length) {
for (var j = 0; j < pages.length; j++) {
const pageId = parseInt(pages[j].id.replace("page", ""))
if (pageId != destPage) {
// This is not the destination page
if (!pages[j].className.includes("blog-hidden")) {
pages[j].className += " blog-hidden"
}
} else {
// This is the destination page
pages[j].className = pages[j].className.replace(" blog-hidden", "")
}
}
scrollToTop();
}
onButtonClick(this);
});
}
links[currentPage].className += " active"
if (currentPage > 0) {
links[currentPage].click();
}
onButtonClick(links[currentPage]);
}
}

0 comments on commit 02ecc24

Please sign in to comment.