var page_container = document.getElementById("page-container");
function go_to_page(pagenumber) {
page_num = pagenumber;
start = max_items*(page_num-1);
if (item_count <max_items*page_num){
end = item_count;
} else {
end = max_items * page_num;
}
populate_page()
var page_count = Math.ceil(item_count/max_items);
if (page_count > 1) {
var min = 1 + page_num - 6;
var max = page_num + 6;
var prev = page_num - 1;
var next = page_num + 1;
if (min <= 1) {
min = 2;
}
if (max >= page_count) {
max = page_count;
}
var pagination_bars = document.getElementsByClassName("pagination");
for (let i = 0; i <pagination_bars.length;i++){
pagination_bars[i].innerHTML = "";
if (page_num != 1) {
var prev_item = `<liclass="page-item"><buttonname="page"value="${prev}"class="page-link"onclick="offset_page(-1)"><imgsrc="/static/svg/chevron-left.svg"></button></li>`;
pagination_bars[i].innerHTML += prev_item;
}
first_active = "";
if (page_num == 1) {first_active = "active"}
var first_item = `<liclass="page-item ${first_active}"><buttonname="page"value="1"class="page-link"onclick="go_to_page(1)">1</button></li>`;
pagination_bars[i].innerHTML += first_item;
if (min > 2) {pagination_bars[i].innerHTML += "...";}
for (x = min; x <max;x++){
active = "";
if (page_num == x) {active = "active"}
var item = `<liclass="page-item ${active}"><buttonname="page"value="${x}"class="page-link"onclick="go_to_page(${x})">${x}</button></li>`;
pagination_bars[i].innerHTML += item;
}
if (max <page_count){pagination_bars[i].innerHTML+="...";}
last_active = "";
if (page_num == page_count) {last_active = "active"}
var last_item = `<liclass="page-item ${last_active}"><buttonname="page"value="1"class="page-link"onclick="go_to_page(${page_count})">${page_count}</button></li>`;
pagination_bars[i].innerHTML += last_item;
if (page_num != page_count) {
var next_item = `<liclass="page-item"><buttonname="page"value="${next}"class="page-link"onclick="offset_page(1)"><imgsrc="/static/svg/chevron-right.svg"></button></li>`;