Suggested Desert Adventures Tours
shouldScroll = true; // Enable scrolling for pagination clicks
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 gap exists
}
}
// Add middle range of pages
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 gap exists
}
$("#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 = $("
")
.addClass("pageno")
.toggleClass("active", isActive);
const pageLink = $("")
.attr("href", "#resultbar")
.text(text)
.attr("data-page", page)
.click(function (e) {
e.preventDefault();
shouldScroll = true; // Enable scrolling for filtering
fetchTours(page, shouldScroll);
});
pageItem.append(pageLink);
return pageItem;
}
}
});
-->