");
},
});
}
function updatePagination(pagination) {
if (!pagination) {
$("#paged").hide();
return;
}
const currentPage = pagination.current_page;
const lastPage = pagination.last_page;
const maxVisiblePages = 5; // Number of visible pages before showing "..."
$("#paged").empty();
// Add the "Previous" button
if (currentPage > 1) {
$("#paged").append(createPageItem("«", currentPage - 1, false));
}
let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
let endPage = Math.min(lastPage, currentPage + Math.floor(maxVisiblePages / 2));
// Ensure first page is always shown, but not duplicated
if (startPage > 1) {
$("#paged").append(createPageItem(1, 1, currentPage === 1));
if (startPage > 2) {
$("#paged").append('
...
'); // Add "..." if there's a gap
}
}
// Add middle range of pages (avoid duplicating '1')
for (let page = startPage; page <= endPage; page++) {
$("#paged").append(createPageItem(page, page, currentPage === page));
}
// Ensure last page is always shown, but not duplicated
if (endPage < lastPage) {
if (endPage < lastPage - 1) {
$("#paged").append('
...
'); // Add "..." if there's a gap
}
$("#paged").append(createPageItem(lastPage, lastPage, currentPage === lastPage));
}
// Add the "Next" button
if (currentPage < lastPage) {
$("#paged").append(createPageItem("»", currentPage + 1, false));
}
$("#paged").show();
function createPageItem(text, page, isActive) {
const pageItem = $("
Now is the time to begin planning your next adventures in Asia. Our Travel Specialists are ready to take your call and discuss the perfect getaway you have been dreaming of.